我对它疯狂:错误:不能过渡到抽象状态。

时间:2022-09-18 23:00:40

Hi I 'm developing an app with IONIC Framework and am developing the user validation and error have not let me go , I leave some details of logic I'm using:

你好,我正在开发一个带有IONIC框架的应用程序,正在开发用户验证和错误,我没有让我去,我留下了一些我正在使用的逻辑的细节:

app.js:

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:

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');
    });
    });

The error is:

错误的是:

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)

Te line in app.js is that:

在app.js中的Te行是:

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

Here I do not include services , constants, controls , policies, and others, if they consider it necessary I do know and update the question. Please i don't do! Help me

在这里,我不包括服务、常量、控制、策略和其他,如果他们认为有必要的话,我知道并更新问题。请我不做!帮助我

2 个解决方案

#1


0  

Well if you open your broswer on '/' the only matching state is your abstract one. Since it's matching otherwise doesn't get executed.

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

Use this instead of otherwise to redirect to your dashboard.

使用它而不是其他方式重定向到您的仪表板。

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

urlRouterProvider美元。当(' / ',/主/ dashboard);

#2


0  

I think your problem is due to your $stateChangeStart method.

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

In case it enters the first couple of if conditions, this line:

如果它进入第一对if条件,这条线:

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

Will abourt your try to go to /main/dashboard, and the state will remain in /.

你的试着去/主/仪表板,这个州将会留在/。

#1


0  

Well if you open your broswer on '/' the only matching state is your abstract one. Since it's matching otherwise doesn't get executed.

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

Use this instead of otherwise to redirect to your dashboard.

使用它而不是其他方式重定向到您的仪表板。

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

urlRouterProvider美元。当(' / ',/主/ dashboard);

#2


0  

I think your problem is due to your $stateChangeStart method.

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

In case it enters the first couple of if conditions, this line:

如果它进入第一对if条件,这条线:

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

Will abourt your try to go to /main/dashboard, and the state will remain in /.

你的试着去/主/仪表板,这个州将会留在/。