可以说我有一个组件结构是这样的:角ngDoCheck()被调用,即使ChangeDetectionStrategy.OnPush
AppComponent
HeaderComponent
ContentComponent
TodosComponent
TodoComponent
如果我设置HeaderComponent的changeDetection
到ChangeDetectionStrategy.OnPush
和改变TodoComponent东西,仍然HeaderComponent的ngDoCheck()
,ngAfterViewChecked()
和ngAfterContentChecked()
被触发。
我缺少什么? ngDoCheck是否被触发?如果是,如何确定组件是否被ChangeDetection检查?
这取决于什么被改变,但你应该看看这两个链接,因为他们解释可能发生的细节。 https://stackoverflow.com/questions/38629828/what-is-the-difference-between-onchanges-and-docheck-in-angular-2 https://stackoverflow.com/questions/39795634/angular-2-变化检测和changedetectionstrategy-onpush。 基于这些看起来,无论您的更改检测策略如何,都会触发'ngDoCheck'。 – eminlala
因此[我的回答](https://stackoverflow.com/a/45522199/2545680)有帮助吗? –