javascript - $emit, $broadcast, prototypical inheritance -


still on basics of angularjs, understand concepts, however, looking @ custom events,

$emit  

and

$broadcast  

for nested controller..

according docs, $emit bubbles event, ie. passes chain, nested controllers,

my question, is, how different calling function parent controller (prototypical inheritance). or have miss understood something?

the thing is, can't direct parent, 1 want call. it's easy break code kind of anti-pattern.

and must agree

$scope.$parent.$parent.$parent.dosomething();  

is pretty ugly.

instead can $emit event upwards, doesn't matter how far chain parent controller is, long listening , reacting.

this gives nice loose coupling between controllers, , acts message pump.

the same goes $broadcast, downwards instead, , here argue more important.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -