2017-10-09 11 views
0

, 내가 변경 키를 얻는 방법

$scope.$watch('bigObject', function(newVal, oldVal, scope) { //Watch the whole object 
    console.log("The key that changed was: " + key); 
}, true); //Deep watch 

를 얻으려면?

예 출력 : 이것에 대한 The key that changed was: bigObject.users.john.birthday

+1

내가 ([두 개체 사이의 일반 깊은 DIFF]을 사용하여 생각하는 것 https://stackoverflow.com/a/25651677/ 2435473) –

답변

0

시도 :

$scope.$watch('bigObject', function (newValue, oldValue, scope) { 
    //Do anything with $scope.letters 
    if(oldValue.users.john.birthday == newValue.users.john.birthday){ 
     //nothing chages 
    } 
    else{ 
     // write your logic here after changinging value  
     } 
      console.log(newValue.users.john.birthday); 
    }); 
+0

감사하지만 값 자체를 얻으려고하지는 않습니다. 내가 바꾼 열쇠를 얻으려고하고있어. – adelriosantiago

+0

하지만 사용자, 개체에 john 개체가 있어야하고 john 개체에 생일 속성이 있어야 함을 보증해야합니다. –

+0

그래서 이전 값과 새 값을 비교하면 –