2

If I want to call a function in a controller when I make changes in a different controller, I usually use $on and $broadcast.

However, I've started using $watch more recently. Now, I have a variable in a service, for example this.shouldIReload = false. Whenever I make a certain change(for example, deleting an item in a modal), I change the value in the service, and using $watch, I can call a reload function in another controller. This works.

Which way is better? What are the pros and cons of each?

  • If you structure your service correctly you shouldn't even have to use `$watch()` explicitly because Angular will handle it during each digest cycle. Personally, I recommend avoiding the use of `$on`, `$broadcast` and `$watch` unless what you are doing simply can't be achieved without using one or more of those methods. – Lex Aug 08 '16 at 20:07

0 Answers0