gpt4 book ai didi

javascript - 我对它很着迷 : Error: Cannot transition to abstract state

转载 作者:行者123 更新时间:2023-11-28 06:29:06 25 4
gpt4 key购买 nike

您好,我正在使用 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 中的一行是:

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

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

最佳答案

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

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

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

将中止您访问 /main/dashboard 的尝试,并且状态将保留在 / 中。

关于javascript - 我对它很着迷 : Error: Cannot transition to abstract state,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34862903/

25 4 0
文章推荐: javascript - 如何使 "Select"文本在下拉菜单中不可见(由