Tuesday 15 April 2014

angularjs - How to detect removed item in $scope.$watch? -


Is this $ scope? $ Watch?

  var data = [{id: 1}, please see the examples given below:  

There is no way to find out the items removed or added items, {Id: 2}, {id: 3}]; $ Scope $ Watch (function () {return data}, function (newValue, oldValue) {console.log (newValue, oldValue); // I want to find out or add here: // var removedItem = ...? // Var added element = ...?}, True) data.push ({id: 4}); Data.splice (0, 1);

Thanks

This code works best for me < / P>

  x = [] $ rootScope. $ Watch ((-> -), (newview, old value) -> change = newValue.filter (item, index) -> return old value [index] and angular.equals (item, old value [Index]) is not added) new = valuefilter ((item, index) - & gt; old do not returnwhole [index]) removed = oldviewfilter (item, index) - & gt; No new [return] [index] do not return) console.log ('x', revenge, added, has been deleted), yes)  

No comments:

Post a Comment