Reputation: 4868
I have an array of objects, something like:
$scope.arr = [{firstName: 'foo', lastName: 'bar'}, {firstName: 'john', lastName: 'doe'}]
I want to use $scope.$watch
to watch only the firstName member in the array items. Something like $scope.$watch('arr[*].firstName', ... )
. Is it possible?
Thanks!
Upvotes: 0
Views: 56
Reputation: 691735
you could simply have the following function in your scope:
$scope.getFirstNames = function() {
return $scope.arr.map(function(element) {
return element.firstName;
});
}
And then use
$scope.$watch('getFirstNames()', ...
Upvotes: 1