Working in an Angular project I realized that when I used a method as the expression to be evaluated in a *ngIf
directive, the method was called multiple times. Looking into the reason I found that it's normal and expected behavior, it will call on every change detection cycle:
- using-a-function-in-ngif-runs-several-times-instead-of-once
- angular2-ngif-afunctioncall-results-in-the-function-being-called-9-times
The question then is: what type of expression should be used in this and others directives? A component variable (undefined|defined|true|false|...), a method returning a boolean, it depends on the implementation?
Does anyone know of any blog or best practices article where this topic is discussed and what they recommend?
Thanks.