2014-03-06 31 views
2
//my controller using $resource factory variable ownerSrvc 
Owner.factory('OwnerSrvc', function($resource){ 
    return $resource('/owner/:id', { 

      query: { method: 'GET', isArray: true }, 
      create: { method: 'POST' }, 
      show: { method: 'GET', isArray:true}, 
      update: { method: 'PUT', params: {id: '@id'} }, 
      delete: { method: 'DELETE', params: {id: '@id'} } 
     } 
    ) 
}); 

Owner.controller('ownerCtrl', function($scope, OwnerSrvc, $location){ 
    OwnerSrvc.query({id:'531784367883254406700e99'},function(data) { 
     // console.log(data[0]);  retrievig data of Mr. Ali 
     $scope.owner = data[0];  binding works here at controller level; 
    }); 

    //User defined function at Congtroller level 

    $scope.editUser=function(ids){ //when i called this function later with id 
     OwnerSrvc.query(//params{id:ids}, //my service giving me result fine 
      function(data) { 
       console.log(data[0]);     //result showing in console OK i.e. Mr. Zain 
       $scope.owner = data; // but data not binding with $scope.owner 

      }); 

     console.log($scope.owner) // here after Query called, $scope.owner showing old result i.e Mr. Ali instead of Mr. Zain 
     $location.path('/owner'); 
    }; 
}); 

我的問題是爲什麼數據在控制器內的功能級別上沒有綁定。以及如何與$scope.owner綁定新的數據?

+0

請更正格式。 – SteAp

回答

0

看來你不分配的功能裏面相同的屬性。

在ctrl上你的代碼是: $ scope.owner = data [0];

裏面的功能edituser: $ scope.owner =數據;

而且功能edituser裏面你評論 // {PARAMS ID:IDS},

如果你不想使用PARAM你應該寫至少{},

相關問題