What is ChangeDetectionStrategy in Angular2 and when to use OnPush Vs Default?

前端 未结 5 1493
故里飘歌
故里飘歌 2020-12-15 09:16

I happened to see ChangeDetectionStrategy in the ngrx documentation. It uses OnPush.

What is ChangeDetectionStrategy in Angula

5条回答
  •  粉色の甜心
    2020-12-15 10:07

    Use OnPush strategy if your objects are immutable and you don't change the state of the objects in your component. It will perform better rather than default where each change of the object makes run change detector to resolve changes. More or less similar is described in Change Detection Strategy: OnPush

    To inform Angular that we are going to comply with the conditions mentioned before to improve performance, we will use the OnPush change detection strategy

    The Angular docs said

    ChangeDetectionStrategy:

    • OnPush means that the change detector's mode will be set to CheckOnce during hydration.

    • Default means that the change detector's mode will be set to CheckAlways during hydration.

提交回复
热议问题