You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
and there is a watchCollection defined in the controller where it will be triggered when a checkbox status is changed
$scope.$watchGroup(['checkbox-1', 'checkbox-2', 'checkbox-3'], function (newValue, oldValue) {
console.log('checkbox-1: new - ' + newValue[0] + ' old - ' + oldValue[0]);
console.log('checkbox-1: new - ' + newValue[1] + ' old - ' + oldValue[1]);
console.log('checkbox-1: new - ' + newValue[2] + ' old - ' + oldValue[2]);
});
But when the checkboc values are updated again and again, the old value list of the $watchCollection is not updated properly and it keep populated with the old values.
e.g.
all check boxes are un-tick initially
tick on the 1st checkbox -> oldValue = [false, false, false], newValue = [true, false, false]
tick the 2nd checkbox now -> oldvalue = [false, false, false], newValue = [true, true, false]
In the old value list, the first value should be true since we changed it in the first operation to true. But its still the initial one
I know i can resolve this by updating the check box variables with a model value and adding a watch for model. Would be great anyone have any ideas to resolve this using the $watchCollection approach ?
I have an html file which has 3 check box values
and there is a watchCollection defined in the controller where it will be triggered when a checkbox status is changed
But when the checkboc values are updated again and again, the old value list of the $watchCollection is not updated properly and it keep populated with the old values.
e.g.
all check boxes are un-tick initially
tick on the 1st checkbox -> oldValue = [false, false, false], newValue = [true, false, false]
tick the 2nd checkbox now -> oldvalue = [false, false, false], newValue = [true, true, false]
In the old value list, the first value should be true since we changed it in the first operation to true. But its still the initial one
I know i can resolve this by updating the check box variables with a model value and adding a watch for model. Would be great anyone have any ideas to resolve this using the $watchCollection approach ?
JSFiddle - https://jsfiddle.net/a0h5nujo/
The text was updated successfully, but these errors were encountered: