我正在尝试使用$state
. 我无法让它工作。这是我的代码:
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ng-token-auth'])
.run(function($ionicPlatform, $location, $rootScope, $state) {
$ionicPlatform.ready(function($state) {
$rootScope.$on('auth:login-success', function($state) {
console.log('success event triggered yo main');
// $location.path('main');
$state.go('main');
});
});
})
.config(function($stateProvider, $urlRouterProvider, $authProvider) {
$stateProvider
// setup an abstract state for the tabs directive
.state('main', {
url: '/main',
templateUrl: 'templates/main.html'
})
.state('home', {
url: '/home',
templateUrl: 'templates/home.html'
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/home');
});
这给了我以下错误:
ionic.bundle.js:25642 TypeError: $state.go is not a function
at app.js:28
at Scope.$broadcast (ionic.bundle.js:29477)
at ng-token-auth.js:191
at ionic.bundle.js:23384
at processQueue (ionic.bundle.js:27879)
at ionic.bundle.js:27895
at Scope.$eval (ionic.bundle.js:29158)
at Scope.$digest (ionic.bundle.js:28969)
at Scope.$apply (ionic.bundle.js:29263)
at done (ionic.bundle.js:23676)
我尝试从 $rootScope.$on 中删除 $state 但我收到了这个错误:
ionic.bundle.js:25642 TypeError: Cannot read property 'go' of undefined
at app.js:28
at Scope.$broadcast (ionic.bundle.js:29477)
at ng-token-auth.js:191
at ionic.bundle.js:23384
at processQueue (ionic.bundle.js:27879)
at ionic.bundle.js:27895
at Scope.$eval (ionic.bundle.js:29158)
at Scope.$digest (ionic.bundle.js:28969)
at Scope.$apply (ionic.bundle.js:29263)
at done (ionic.bundle.js:23676)
我该如何解决?