我对这个问题感到很沮丧,这是我的app.js:
angular.module('starter', ['ionic','config'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider.state('main', {
url: '/',
controller: 'main',
templateUrl: 'index.html'
});
$stateProvider.state('products', {
url: '/products',
templateUrl: 'products.html'
});
});
这是我的控制器
.controller('main', function ( $scope, $ionicModal, $state, $http) {
并使用 $ state.go('产品&#39);
或
$state.go('products', {});
或
ui-sref="products"
所有这些都会提示此错误:
Error: Could not resolve 'main' from state ''
at Object.transitionTo (angular-ui-router.js:3074)
at Object.go (angular-ui-router.js:3007)
at Scope.$scope.adds (main-controller.js:12)
at fn (eval at <anonymous> (ionic.bundle.js:27615), <anonymous>:4:203)
at ionic.bundle.js:65290
at Scope.$eval (ionic.bundle.js:30372)
at Scope.$apply (ionic.bundle.js:30472)
at HTMLButtonElement.<anonymous> (ionic.bundle.js:65289)
at defaultHandlerWrapper (ionic.bundle.js:16764)
at HTMLButtonElement.eventHandler (ionic.bundle.js:16752)(anonymous function) @ ionic.bundle.js:26771(anonymous function) @ ionic.bundle.js:23484Scope.$apply @ ionic.bundle.js:30477(anonymous function) @ ionic.bundle.js:65289defaultHandlerWrapper @ ionic.bundle.js:16764eventHandler @ ionic.bundle.js:16752triggerMouseEvent @ ionic.bundle.js:2953tapClick @ ionic.bundle.js:2942tapTouchEnd @ ionic.bundle.js:3069
然而,我的所有状态总是被提示为&#34; undefined&#34;当呼唤状态时,或者通常从一边移动到一边,基本上我已经尝试了我在这一边发现的一切,但是没有工作。绝对没有,因为一些不明原因,它只是没有加载主要状态作为主要的&#39;也不会加载到主要产品或产品或任何状态,如果通过网络访问,则可以看到这些页面。
导入和名称出错,必须将控制器更改为starter.ctrl并放入启动器[&#39; ionic&#39;,&#39; ui.router&#39;,&#39; stater.ctrl& #39;]然后它奏效了。