且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当[值]更改时,为什么这里没有发生更改检测?

更新时间:2022-03-31 07:40:51

由于使用 onPush 进行更改检测,因此在更改输入或处理已侦听的事件时会运行.

Because with onPush change detection runs when an input is changed or when an event that was listened to was handled.

如果更改 this.testData ,则需要运行更改检测以更新 [value] ="testData" 绑定.如果发生这种情况,将对< p-dataTable> 运行更改检测,因为其输入已更改.

If you change this.testData, then change detection needs to run to update the [value]="testData" binding. If that happens, change detection will run for <p-dataTable> because its input changed.

App 上没有更改的输入,因此没有更改检测.

There is no input on App that has changed, therefore no change detection.

您可以使用 ChangeDetectorRef.markForCheck()

> 柱塞示例