Skip to content Skip to sidebar Skip to footer

Why *ngif In Angular 2 Always Is Executing When Use Function?

I'm trying to create a application with angular 2,and have a auth service in my application , my html template is somthing like this:

Solution 1:

Every time Angulars change detection is run, it evaluates all bindings and therefore calls your functions to check if the view needs updating.

Using functions in bindings is discouraged. Either assign the value to a property of your component class and bind to this property instead, or use observables and the | async pipe to notify Angular about changed values.

Another option is to use ChangeDetectionStrategy.OnPush where Angular change detection is only run when an input value has changed.

Post a Comment for "Why *ngif In Angular 2 Always Is Executing When Use Function?"