2014-03-06 2 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

이 서식을 수정하십시오를 작성해야 PARAM를 사용하지 않을 경우,

:

는 또한 기능 edituser 안에 당신은 // PARAMS {식별자 ID를} 댓글을 달았습니다. – SteAp

답변

0

함수 내에 동일한 속성을 지정하지 않은 것처럼 보입니다.

코드에서 코드는 다음과 같습니다. $ scope.owner = data [0];

편집 사용자 기능 : $ scope.owner = data; 당신은 적어도 {},

관련 문제