当[值]更改时,为什么这里没有发生更改检测? [英] Why is change detection not happening here when [value] changed?

查看:53
本文介绍了当[值]更改时,为什么这里没有发生更改检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的朋克: https://plnkr.co/edit/QPqciUngXeby2uECbokx?p=预览(您可能必须单击停止"并运行几次才能使其正确加载)

Here is my plunker: https://plnkr.co/edit/QPqciUngXeby2uECbokx?p=preview (You might have to click on stop and run a few times for it to load properly)

表格未更改.

但是当您服用

changeDetection: ChangeDetectionStrategy.OnPush

退出,表格发生变化.

我的理解是,使用OnPush,当@Input更改时,更改检测将触发.在这种情况下,@ Input是[value],它链接到this.testData.

My understanding is that with OnPush, when the @Input changes, change detection will fire. In this case, the @Input is [value], which links to this.testData.

为什么不更改?

推荐答案

由于使用 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()

> 柱塞示例

这篇关于当[值]更改时,为什么这里没有发生更改检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆