angular2 - infinite loop when i call method from a Angular 2 class inside template

I have a problem when i call a method from component in the template by interpolation: {{get_method()}}. The method runs, but in infinite loop I don't know why. Any help please ??

the code of method is like this :

get_name() {
  console.log("bonjour");
}

and I call it in my template like this :

{{get_name()}}

and this is the result :

enter image description here


Solution 1:

You should not use methods in your template, because each time Angular runs change detection, the method will be called, which can happen often. So actually this is not an infinite loop, the method just gets called on each change detection.

To avoid this, you need to change your code to handle the logic of methods in your component, and use variables in your template instead.

Solution 2:

i finally found the sollution , it's to change Detection Strategy to OnPush for more information visite this link Change Detection Strategy: OnPush