Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$emit $broadcast synchronous or asynchronous?

Are $scope.$emit() and $scope.$broadcast() synchronous or asynchronous in the literal sense?

For example, in the cases

$scope.$emit()
console.log(" I am finished sending events");

and

$scope.$broadcast()
console.log(" I am finished sending events");

If all the listeners are synchronous (have no ajax calls etc) will the logging only happen after all listeners receive their events?

like image 814
Breako Breako Avatar asked Aug 08 '13 15:08

Breako Breako


People also ask

Is angular sync or async?

A common misconception in Angular development is regarding whether observables are synchronous or asynchronous. A lot of (even experienced Angular developers) think that observables are async, but the truth is that they can be… Both synchronous and asynchronous.

What is $emit $broadcast and $on in AngularJs?

Broadcast: We can pass the value from parent to child (i.e parent -> child controller.) Emit: we can pass the value from child to parent (i.e.child ->parent controller.) On: catch the event dispatched by $broadcast or $emit .

Is angular asynchronous by default?

AngularJs supports async requests by default.


1 Answers

They are synchronous.

See also https://groups.google.com/d/msg/angular/yyH3FYAy5ZY/APANNMnolD8J

like image 175
Mark Rajcok Avatar answered Oct 15 '22 14:10

Mark Rajcok