What is 'cheaper' performance-wise $broadcast or $watch

后端 未结 1 975
一整个雨季
一整个雨季 2020-12-01 14:00

I have a situation in my application where I need to reload the menu each time the role of the user changes(One user can have roles in several companies).

I was wond

相关标签:
1条回答
  • 2020-12-01 14:31

    $watch() is doing dirt-checking: the function makes a comparison each digest cycle. On the other hand, $broadcast() propagates an event only when there is one. Naturally, $broadcast() is cheaper than $watch().

    But did you really have to worry about performance here? One primitive comparison by cycle is nothing. However, conceptually, $watch() is clearly what you need: you want to do an action each time a variable changes. I can't imagine using $broadcast() here.

    0 讨论(0)
提交回复
热议问题