Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

Is there a way to subscribe to events on multiple objects using $watch

E.g.

$scope.$watch('item1, item2', function () { });

1 Answer

0 votes
by (106k points)

Yes, there is a way to subscribe to events on multiple objects using $watch in AngularJS 1.3 there's a new method called $watchGroup for observing a set of expressions. 

See the code example below:-

$scope.foo = 'foo';

$scope.bar = 'bar';

$scope.$watchGroup(['foo', 'bar'], function(newValues, oldValues, scope) { 

});

Related questions

+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 31, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
asked Aug 27, 2019 in Web Technology by Sammy (47.6k points)

Browse Categories

...