techguy2000
techguy2000

Reputation: 5161

Why is change detection not happening here when [value] changed?

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)

The table is not changing.

But when you take

changeDetection: ChangeDetectionStrategy.OnPush

out, the table changes.

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.

Why is it not changing?

Upvotes: 1

Views: 2005

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657308

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

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.

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

You can mark App for check using ChangeDetectorRef.markForCheck()

Plunker example

Upvotes: 1

Related Questions