2017-10-09 60 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

但它應該保證你的用戶,對象必須有約翰對象和約翰對象必須有生日特性 –

+0

所以@ @你只是comapare舊值到新值 –