I have this data
in my controller
$scope.data = {
home: {
baseValue: "1",
name: "home"
},
contact: {
baseValue: "2",
name: "contract"
}
// a lot more options
};
with some html like this:
<section class="content row" ng-repeat="item in data">
{{item.name}}
....
</section>
Now, I want to know when the baseValue
is changed but because of I using a objects inside the data variable I can not watch
the property in a simpler way.
I have tried something like this, but I have to loop all the array
$scope.$watch('data', function (newValue, oldValue, scope) {
// some code to compare the tow arrays, line by line
}, true);
How can I do a simpler $watch
to know only when the baseValue
is changed?
Similar questions:
- AngularJS watch array of objects for data change
- How to get an object that was changed in angularjs?
- How to deep watch an array in angularjs?
UPDATE 1
I could add an individual watch for each object to know when the baseValue
is changed, but it won't be nice if I had an n
number of objects, not only a couple of objects like in this example
$scope.$watch('data.home', function (newValue, oldValue, scope) {
// do some stuff with newvalue.baseValue
}, true);
$scope.$watch('data.contact', function (newValue, oldValue, scope) {
// do some stuff with newvalue.baseValue
}, true);
... // Adds more individual `watch`