2016-03-21 51 views
1

我新的角度,我不明白爲什麼我的數據不是從控制器發送到另一個狀態參數我有我的控制檯「undefined」。你能幫我解決這個問題嗎?

我的控制器:

 .controller('RegistreCtrl', function ($scope, $stateParams,factotransaction,$state) { 
      console.log("coucou"); 
      var mytoken = sessionStorage.getItem('token'); 
      factotransaction.send(mytoken).then(function(conf) 

      { 
        console.log(conf); 
        $scope.datab = conf.data; 
      }) 

      $scope.operation = function(id){ 



       $state.go('app.operation', { id: id }); 
       $state.params.id = id; 



      } 

    }) 


     .controller('OperationCtrl', function ($scope, $stateParams,factotransaction,$state) { 



      var mytoken = sessionStorage.getItem('token'); 
      factotransaction.send(mytoken).then(function(conf){ 
       console.log(conf); 
       conf.data.forEach(function(item){ 
       console.log($state.params.id); 
        if($state.params.id == item.id) { 

         $scope.item = item; 
         console.log(item); 
        } 
       }); 
      }); 

我app.js:

.state('app.operation', { 
     url: '/operation', 
     views: { 
      'menuContent': { 
      templateUrl: 'templates/operation.html', 
      controller: 'OperationCtrl' 
       } 
      } 
     }) 
; 
+0

嘗試'$ state.current.params.id',並將狀態的url更改爲'url:'/ operation /:id',' –

+0

哇!問題是網址!把它作爲答案,然後我會驗證:) – xenurs

+0

謝謝,但我沒有足夠的時間寫一個完整的寫得很好的問題。很高興我能夠幫助:) –

回答

0

我建議包括PARAMS在路由本身第一。

.state('albums.name',{ 
 
      //url:'', 
 
      templateUrl:'views/tpls/player.tpl.html', 
 
      controller:'playerCtrl as vm', 
 
      params:{ 
 
       album:null, 
 
      } 
 
     });

i上如何對象稱爲專輯傳遞到路線實施例。