0 votes
1 view
in Web Technology by (47.8k 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 (107k 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.8k points)
0 votes
1 answer
asked Aug 27, 2019 in Web Technology by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...