I have this data in my controller
$scope.data = { home: { baseValue: "1", name: "home" }, contact: { baseValue: "2", name: "contract" }
with some html as follows:
<section class="content row" ng-repeat="item in data"> {{item.name}} .... </section>
Now I want to know when the baseValue changes, but due to the fact that I use objects inside the data variable, I can not watch property in a simpler way.
I tried something like this, but I need to loop the entire array
$scope.$watch('data', function (newValue, oldValue, scope) {
How can I make a simpler $watch to know only when changing baseValue ?
Related questions:
- AngularJS object view arrays to modify data
- How to get an object that has been modified in angularjs?
- How to deeply observe an array in angularjs?
UPDATE 1
I could add an individual clock for each object to know when the baseValue changes, but it would not be good if I had the number of objects n , and not just a few objects like 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`
javascript angularjs
Coyolero Jul 22 '14 at 0:18 2014-07-22 00:18
source share