简体   繁体   English

使用CD类进行角度2变化检测

[英]angular2 change detection with CD class

How angular2 perform change detection default strategy ? angular2如何执行变更检测默认策略? I have gone through some post related with the change detection and got some details like 'angular2 creates change detector for every component'. 我已经阅读了一些与变化检测相关的帖子,并获得了一些细节,例如'angular2为每个组件创建变化检测器'。

Now for instance If I've 4 components (comp1, comp2 comp3 & comp4) and I change comp4 property so change detection would be perform through all components or single component ? 例如,如果我有4个组件(comp1,comp2 comp3和comp4)并且我更改了comp4属性,那么更改检测将通过所有组件或单个组件执行?

Can you please provide some code tutorial link related above info ? 您能否提供一些与上述信息相关的代码教程链接?

Here is the detailed article that will help you understand change detection: 以下是详细的文章,可帮助您了解更改检测:

Also see this answer . 另见这个答案

Now for instance If I've 4 components (comp1, comp2 comp3 & comp4) and I change comp4 property so change detection would be perform through all components or single component ? 例如,如果我有4个组件(comp1,comp2 comp3和comp4)并且我更改了comp4属性,那么更改检测将通过所有组件或单个组件执行?

If you change the comp4 property as a result of some async opertation like setTimeout , the change detection will run from root level component and down to children. 如果由于某些异步操作(如setTimeout )而更改comp4属性,则更改检测将从根级别组件运行并向下运行到子级。 So you will have change detection for all components. 因此,您将对所有组件进行更改检测。

If some of the components set ChangeDetectionStrategy.OnPush , they will be skipped if the input bindings haven't changed. 如果某些组件设置了ChangeDetectionStrategy.OnPush ,则在输入绑定未更改时将跳过它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM