Angular2中的ChangeDetectionStrategy是什么?何时使用OnPush Vs Default? [英] What is ChangeDetectionStrategy in Angular2 and when to use OnPush Vs Default?

查看:136
本文介绍了Angular2中的ChangeDetectionStrategy是什么?何时使用OnPush Vs Default?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然在 ngrx文档ChangeDetectionStrategy .它使用OnPush.

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

什么是Angular2中的ChangeDetectionStrategy?何时使用OnPush Vs Default?

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

推荐答案

如果对象是不可变的,并且不更改组件中对象的状态,请使用OnPush策略.在对象的每次更改使运行更改检测器解决更改的情况下,它的性能要好于默认值. 变更检测策略:OnPush

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

为通知Angular我们将遵守前面提到的条件以提高性能,我们将使用OnPush更改检测策略

Angular文档说

The Angular docs said

ChangeDetectionStrategy:

  • OnPush意味着在水合作用期间将更改检测器的模式设置为CheckOnce.

ChangeDetectionStrategy:

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

Default意味着在水合作用期间将更改检测器的模式设置为CheckAlways.

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

这篇关于Angular2中的ChangeDetectionStrategy是什么?何时使用OnPush Vs Default?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆