angularjs-uirouter $ state.go错误为.go undefined

时间:2017-12-09 12:21:06

标签: angularjs angular-ui-router

这里imgetting错误$statechangStart这里我试图在$ statechageStart中检查我的凭据

.config(function ($stateProvider, $urlRouterProvider) {
        $stateProvider
         .state('Login',{
                url:'/LoginService',
                templateUrl: '/ApiClient/Home/LoginPage.html',
                controller:'LoginController'

            })
  $urlRouterProvider.otherwise('/')
    })

     .run(function ($rootScope) {
            $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams, options, $scope, $state) {
                debugger;
                if (toState.module == "Private" && sessionStorage.getItem('employee')!=null) {}

                else {
                    event.preventDefault();
                     $state.go('Login');
                }

1 个答案:

答案 0 :(得分:0)

您需要将 $state 注入.run,否则未定义

.run(function ($rootScope, $state) 

修改

在$ stateChangeStart事件中使用$ state.go是一种不好的做法。出于您的目的,您最好在设置超时后应用state.go

   $timeout($state.go.bind(null, 'Login'), 3000);