我很生气:错误:无法过渡到抽象状态

时间:2016-01-18 19:50:09

标签: javascript angularjs ionic-framework

您好我正在使用IONIC Framework开发应用程序并开发用户验证并且错误并没有让我离开,我留下了一些我正在使用的逻辑细节:

app.js:

angular.module('skulApp', ['ionic', 'ionic-material', 'ionMdInput', 'ngCordova'])
.run(function($ionicPlatform, $rootScope, $state, AUTH_EVENTS, _Auth_Service, sqliteService){


$ionicPlatform.ready(function(){
if (window.cordova && window.cordova.plugins.Keyboard)
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

    if (window.StatusBar)
        StatusBar.styleDefault();

    sqliteService.preloadDataBase(true);
});

$rootScope.$on('$stateChangeStart', function(event, next, nextParams, fromState) {
    if ('data' in next && 'authorizedRoles' in next.data) {
        var authorizedRoles = next.data.authorizedRoles;
        if (!_Auth_Service.isAuthorized(authorizedRoles)) {
            event.preventDefault();
            $state.go($state.current, nextParams, {reload: true});
            $rootScope.$broadcast(AUTH_EVENTS.notAuthorized);
        }
    }

    if (!_Auth_Service.isAuthenticated()) {
        if (next.name !== 'login') {
            event.preventDefault();
            $state.go('login');
        }
    }
});
})

app.config.js:

.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider, USER_ROLES) {

$stateProvider
.state('main', {
    url: '/',
    abstract: true,
    templateUrl: 'templates/main.html'
})

.state('login', {
    url: '/login',
    templateUrl: 'templates/login.html',
    controller: 'LoginCtrl'
})

.state('main.dashboard', {
    url: 'main/dashboard',
    views: {
        'menuContent': {
            templateUrl: 'templates/dashboard.html',
            controller: 'DashboardCtrl'
        },
        'fabContent': {
            template: '<button id="fab-profile" class="button button-fab button-fab-bottom-right button-energized-900" ui-sref="main.edit"><i class="icon ion-edit"></i></button>',
            controller: function($timeout) {
                $timeout(function() {
                    document.getElementById('fab-profile').classList.toggle('on');
                }, 800);
            }
        }
    },
    data: {
        authorizedRoles: [
            USER_ROLES.admin, 
            USER_ROLES.teacher, 
            USER_ROLES.father
        ]
    }
})

.state('main.edit', {
    url: 'main/edit',
    views: {
        'menuContent': {
            templateUrl: 'templates/edit.html',
            controller: 'EditCtrl'
        },
        'fabContent': {
            template: ''
        }
    }
    });

    $urlRouterProvider.otherwise(function($injector, $location){
        var $state = $injector.get("$state");
        $state.go('main.dashboard');
    });
    });

错误是:

Error: Cannot transition to abstract state '[object Object]'
    at Object.transitionTo (ionic.bundle.js:40332)
    at Object.go (ionic.bundle.js:40262)
    at app.js:52
    at Scope.$broadcast (ionic.bundle.js:23003)
    at Object.transitionTo (ionic.bundle.js:40395)
    at Object.go (ionic.bundle.js:40262)
    at app.config.js:210
    at check (ionic.bundle.js:39247)
    at update (ionic.bundle.js:39259)
    at Scope.$broadcast (ionic.bundle.js:23003)

app.js中的Te行是:

$state.go($state.current, nextParams, {reload: true});

这里我不包括服务,常量,控件,策略等,如果他们认为有必要我知道并更新问题。请我不要做!帮帮我

2 个答案:

答案 0 :(得分:0)

如果你打开你的broswer&#39; /&#39;唯一匹配的状态是你的抽象状态。因为它的匹配否则不会被执行。

使用此方法而非其他方式重定向到信息中心。

$urlRouterProvider.when('/', '/main/dashboard');

答案 1 :(得分:0)

我认为您的问题是由 $ stateChangeStart 方法造成的。

如果它进入前几个 if 条件,则此行:

$state.go($state.current, nextParams, {reload: true});

将继续尝试转到 / main / dashboard ,状态将保留在 /