Should use ChangeDetectionStrategy.OnPush for eveything?

后端 未结 3 1788
感动是毒
感动是毒 2021-01-18 09:41

As the title says: I\'m working on a very big project and in few components I\'ve used ChangeDetectionStrategy.OnPush to avoid bad performances. I was wondering

3条回答
  •  暖寄归人
    2021-01-18 10:27

    Especially with very big projects, the OnPush strategy is recommended to decrease the change detection process that it is a very expensive operation.

    With inherited projects, the recommendation is to start applying the OnPush strategy from the leaf components and check that everything is still working.

    Only at this point, follow the ancestors and go up one level at time to the root. In the end the overall performance will benefit.

    Here there is a very good article about change detection in Angular.

提交回复
热议问题