angularjs - Can $scope.$watch determine equivalency of two objects? -


i've built directive gets data $parse'ing angular expression in 1 of $attrs. expression typically simple filter applied list model, evaluation of change when parent $scope modified.

to monitor when should update data it's using, directive using $scope.$watch call, custom function re-$parse's expression. problem i'm running $parse generate new object instance expression, $watch sees value changed when data in each object equivalent. results in code hitting $digest iteration cap due actions taken in $watch callback.

to around doing following, currently:

 var getter = $parse($attrs.myexpression);  $scope.$watch(function () {     var newval = getter($scope);     if (json.stringify($scope.currentdata) !== json.stringify(newval)) {       return newval;     } else {       return $scope.currentdata;     }   }, function (newval) {     $scope.currentdata = newval;     // other stuff   }); 

however, don't relying on json intermediary here, nor using $watch'ed function evaluate equivalency of old , new values. there flag $watch can take determine if 2 objects equivalent, or there better approach handling kind of situation?

hi should use this,

scope.$watch('data', function (newval) { /*...*/ }, true); 

this has been answerd here on stackoverflow


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -