Answer the question
In order to leave comments, you need to log in
Using $watchCollection to determine the dirty/pristine status of a model
There is a model that is loaded from the server. There is a management page for this model. I would like to enable the "Save" button only with a "dirty" model. Using the possibilities of forms is not very convenient, since there are inputs that are not directly related to the model.
So if I use $watchCollection like this
$scope.$watchCollection('ruleset.rules', function() {
$scope.rulesetChanged = true;
});
$scope.rulesetChanged = false;
var cases = 0;
$scope.$watchCollection('ruleset.rules', function() {
if (cases > 0) {
$scope.rulesetChanged = true;
}
cases ++;
});
$scope.rulesetChanged = false;
Answer the question
In order to leave comments, you need to log in
solved the problem by copying the original model (angular.copy) and the comparison function.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question