Angular2, why functions are called each time I move the mouse

牧云@^-^@ 提交于 2019-12-22 05:53:09

问题


I use Angular2 seed (https://github.com/mgechev/angular2-seed), and I encounter a problem.

Indeed, in my template html, I use some bindings like {{test}} with a variable test in the component, and {{getTest()}} which calls the getTest() function.

If I use a console log in getTest(), each time I move the mouse, I get a log.

Is it the desired behaviour ?

I was thinking it will update only if the value changes, like with an observer. Did I have to use an observer to avoid this call each time ?

Thanks you.


回答1:


Angular2 change detection checks if bindings are updated every time it is run and it is usually run when events that are listened to are fired.

This is why it is discouraged to use method calls in bindings.



来源:https://stackoverflow.com/questions/38583967/angular2-why-functions-are-called-each-time-i-move-the-mouse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!