Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 265
J. Doe Avatar asked Jul 26 '16 07:07

J. Doe


1 Answers

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.

like image 186
Günter Zöchbauer Avatar answered Sep 27 '22 20:09

Günter Zöchbauer