I have a service defined in AngularJS with app.factory("serviceName", function($rootScope) { .. })
If I do $rootScope.$apply(), would that re-evaluate ALL the controller’s scopes in the app or just the scopes of the controllers which use this service?
I have a service defined in AngularJS with app.factory(serviceName, function($rootScope) { .. }) If
Share
$digest() only “flushes” the current scope and all of its child scopes.
$apply(exp) evaluates the exp and then calls $digest() on the root scope. So calling $apply() (on any scope) affects all scopes.
If you call $digest() and your action changes some parent scope, the change will not be observed. So normally you want to call $apply(). (If you’re tempted to try and be more efficient by calling $digest(), it can bite you later!)