0

を使用して簡単なルート リダイレクトを実行しようとしています$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)

これを修正するにはどうすればよいですか?

4

2 に答える 2

0

ui.router モジュールへの依存関係を設定する必要があります。

angular.module('starter', ['ionic', .... , 'ui.router'])
于 2016-04-07T16:09:33.100 に答える