2015-01-04 38 views
0

什麼,我試圖做無法與next和prev參數

作爲問題標題中提到,我想檢查下一個路線的授權和認證,所以我訪問$ locationChangeStart $狀態的自定義屬性已經在路由上定製了屬性並試圖在$ locationChageStart中訪問它們。

問題我面臨的是

eventnextprev/current論點是正確的,但自定義屬性返回undefined

我的代碼

myModule.run(function($rootScope,authService,$state){ 

     $rootScope.$on("$locationChangeStart",function(e,next,prev){ 

      console.log(e+","+next+","+prev); //correct 
      console.log(next.reqAuthentication); // returning undefined 
      console.log(prev.reqAuthentication); // returning undefined 
     }); 
    }) 

和配置路線就像

  .state('profile.company', { 
      url: "/company", 
      templateUrl: 'partials/companyprofile.html', 
      controller: 'adminCtrl', 
      reqAuthentication:true, 
      authenticateRole:['a','b',"c"] 

     }) 
     .state('profile.messages', { 
      url: "/messages", 
      templateUrl: 'partials/chat.html', 
      controller: 'adminCtrl', 
      reqAuthentication:true, 
      authenticateRole:['a','b',"b"] 
      }) 

注:我使用的用戶界面的路線,所以我認爲有一些問題我混合起來用ngRoute

回答

1

您可以使用此:

$rootScope.$on('$stateChangeSuccess', 
function(event, toState, toParams, fromState, fromParams){ ... }) 

,如果你想與各州合作。

更多細節,你可以找到https://github.com/angular-ui/ui-router/wiki

+0

感謝您的回答,我已經嘗試過了fromState.reqAuthentication和toState.reqAuthentication都是undefined – 2015-01-04 13:43:48

+1

謝謝,解決你能解釋一下什麼toParams和fromParams冷藏什麼? – 2015-01-04 13:48:01

+0

也許我一直在toParams和來自Params。你是正確的需要寫從State.reqAuthentication和toState.reqAuthentication。因爲toParams和fromParams允許進入兄弟狀態,該狀態共享在父狀態中指定的參數:http://stackoverflow.com/questions/19516771/state-go-toparams-not-passed-to-stateparams – 2015-01-04 16:41:00