Angular 各种视图的基础类,提供变更检测功能。 变更检测树会收集要检查的所有视图。 使用这些方法从树中添加或移除视图、初始化变更检测并显式地把这些视图标记为脏的,意思是它们变了、需要重新渲染
参考资料:
深入 Angular 的 Change Detection 机制
变化检测策略:OnPush
source code:
`export interface Component extends Directive {
/**
* The change-detection strategy to use for this component.
*
* When a component is instantiated, Angular creates a change detector,
* which is responsible for propagating the component's bindings.
* The strategy is one of:
* - ChangeDetectionStrategy#OnPush sets the strategy to CheckOnce (on demand).
* - ChangeDetectionStrategy#Default sets the strategy to CheckAlways.
*/
changeDetection?: ChangeDetectionStrategy;
当一个组件实例化的时候,ng会创建一个变化检测器,它给出了两种选择,
变化检测策略:OnPush,当使用 OnPush 策略的时候,若输入属性没有发生变化,组件的变化检测将会被跳过,按需检查
默认策略:Default ,一个也不放过,全部弄死,变化检测器的状态值是 CheckAlways.`
当在写一个组件的时候,使用OnPush + ChangeDetectorRef来优化
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。