angularjs - angular watch on object and it's child -


i have on object in directive, let's say:

scope = {     : {         b : [],        c : 5     } }  scope.$watch('a', function awaschanged(){}); scope.$watchcollection('b', function bwaschanged(){}); 

i have watch on , on b. when changed watch of b called well. want when changed "awaschanged" called (even if b changed well) , "bwaschanged" called when b changed.

what mean under a changed.

generally $watch() checks object reference equality not structure.

for example if write like:

$scope.a.ddd = "ddd"; 

the $watch not catch that.

however deep-watch (with flag true) should take care case.

when changed "awaschanged" called...

i suppose mean if c change ... write custom comparator like:

$scope.$watch(function () {        return $scope.a;     },     function (newvalue, oldvalue) {       if(newvalue.c == oldvalue.c){return;} // avoid b       /*...*/      }, true); // object equality (not reference). 

the deep-watch bit expensive wrote way:

scope.$watchcollection('a.b', function bwaschanged(){}); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -