0

Really, I have a dilemma - and I'm sure I'm not the only one. Sometimes I'm conflicted between using $emit/$on communication, and just $watch on a scope to fire events. I am sure the answer is something like "depends on how many listeners etc." - but was wondering if 1:1 there was a better practice?

itamar
  • 3,837
  • 5
  • 35
  • 60

1 Answers1

1

The concept of both are different. So the question title Which is more 'expensive'? $watch or $emit/$on in AngularJS? is not useful as if it is expensive or not.

You can see the documentation in more details.

watch:

Registers a listener callback to be executed whenever the watchExpression changes.

on:

Listens on events of a given type.


So, the watch is used to consider if the variable or object is going to change? Then apply it.

And the on method is used to consider sharing event between each-other. So from parent you can broadcast the event and the child can emit the broadcasted event.


You may also be interested the followings:

watch and apply

working with on

broadcast vs emit

Community
  • 1
  • 1
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231