Using $watchGroup
, how can I determine which expression in the group was changed
$scope.$watchGroup(['dec','bin','oct','hex'], function(newValues, oldValues, scope) {
last_changed = ??? //return which exp was changed in this run...
if(last_changed=='dec') //then something
if(last_changed=='bin') //then something
if(last_changed=='oct') //then something
if(last_changed=='hex') //then something
});
Edit 1:-
--->the problem is i can't unbind the n_vals from the newValues.
var n_vals = [];
$scope.$watchGroup(['dec','bin','oct','hex'], function(newValues, oldValues, scope) {
last_updated = changed_one(newValues,n_vals); //last_updated EXP
n_vals = newValues;
});
Solution:-
n_vals = angular.copy(newValues);
look the following link:
Deep copying objects in angular?
Angular offers
$watchGroup
(since 1.3).Basically, it returns the scope variable
oldValue
andnewValue
in the manner how we put it inwatchGroup
.Use the index of the scope variable to get its respective
newVal
andoldVal
like below.To get
newValue
s of respective scope variables:To get
oldValue
s of respective scope variables:Edit 1
To catch which variable was updated last, you can try below code.
Edit 2:
I have minified the code and made the
I hope this clears things up.