why *ngIf in angular 2 always is executing when use function?

后端 未结 1 1131
-上瘾入骨i
-上瘾入骨i 2021-01-20 22:31

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:

 
&l
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-20 23:17

    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.

    0 讨论(0)
提交回复
热议问题