常见的迷之报错:Expression has changed after checked
参见这篇 https://www.jianshu.com/p/25f79e6245d9
ChangeDetectorRef: (组件a中引用)
返回一个a及以下的viewRef,即视图引用
1、状态(ChangeDetectorStatus)
* FirstCheck* ChecksEnabled* Errored* Destroyed
OnPush:
ChangeDetectionStrategy 设置成 OnPush: 在第一轮变更检测运行后禁止检测, 当父组件绑定属性改变时启用, 在变更检测执行后再禁用。
You probably know that Angular tracks binding inputs by object reference. It means that if an object reference hasn’t changed the binding change is not detected and change detection is not executed for a component that uses OnPush strategy.
如果,binding的object reference引用不变,即使某一个属性变了,也不会触发
2、方法
detechChanges: 自顶向下,执行一轮变更检查,a, aa, ab, ...
detach/reattach: 禁用/启用,对a的变更检查。(如果a的父组件上没有触发检查,那么 a的检查状态的启用,就没有意义)
markForCheck: 自下向上,启用自己及所有父组件(直到根组件)的变更检查,一次????(ChangeDetectorStatus.CheckOnce)
checkNoChanges: 返回“是否没有更新”的bool值
todo:
markForCheck vs detechChanges:
各自适合的应用场景
生命周期:(待完善)

引用:
网友评论