$observe multiple attributes at the same time and fire callback only once

前端 未结 5 1719
灰色年华
灰色年华 2021-02-19 20:38

I wonder is it possible to execute some callback only once after evaluation all (or only some) attributes of directive (without isolated scope). Attributes are really great to p

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-19 21:21

    There are several ways presented to solve this problem. I liked the debounce solution a lot. However, here is my solution to this problem. This combines all the attributes in one single attribute and creates a JSON representation of the attributes that you are interested in. Now, you just need to $observe one attribute and have good perf too!

    Here is a fork of the original plunkr with the implementation: linkhttp://plnkr.co/edit/un3iPL2dfmSn1QJ4zWjQ

提交回复
热议问题