2016-01-18 29 views
0

嗨我正在開發一個應用程序與IONIC框架和開發用戶驗證和錯誤沒有讓我走,我留下一些細節的邏輯我使用:我對它瘋狂:錯誤:無法過渡到抽象狀態

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

我在這裏不包括服務,常量,控制,政策,和其他人,如果他們認爲有必要做我知道並更新問題。請我不這樣做!幫助我

+0

你可以給我們一些背景知道你正在離開什麼狀態,以及當狀態改變處理程序運行時你要去哪個狀態?顯然,它試圖進入你的「主要」狀態,但是當這是一個抽象狀態時,我不清楚'$ state.current'是如何成爲「main」的。 –

+1

使用'$ state.current.name'? –

+0

是的,我使用這一行,但我看到錯誤:錯誤:無法解析''從狀態'' –

回答

0

那麼,如果你在'/'上打開你的瀏覽器,唯一匹配的狀態是你的抽象的。由於它的匹配,否則不會被執行。

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

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

+0

錯誤仍然存​​在,它仍然是一樣的,但我很感謝你的答案:錯誤:無法過渡到抽象狀態'[object對象]' –

0

我認爲你的問題是由於你的$ stateChangeStart方法。

如果它進入了第一對夫婦的如果條件下,該行:

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

將abourt您及早去/主/儀表板,國家將保持在/

+0

好的,所以這個條件是:if($ state.current.name!='') 或者是不同的,我有業餘的角 –