[9.0.0-rc.9] `CdkConnectedOverlay.backdropClick` events do not instigate change detection in `OnPush`
See original GitHub issueReproduction
See this repository as the StackBlitz template is not configured for v9 RC: https://github.com/benelliott/repro-cdk-overlay
Expected Behavior
What behavior were you expecting to see?
CdkConnectedOverlay.backdropClick
events should be emitted within the Angular zone so that they are picked up by ChangeDetectionStrategy.OnPush
.
Actual Behavior
Setting a value in a component based on the backdropClick
event causes no changes under OnPush
without a manual call to ChangeDetectorRef.detectChanges
.
I think this is because in https://github.com/angular/components/blob/master/src/cdk/overlay/overlay-directives.ts#L380 the backdropClick.emit
call needs to be run inside NgZone.run
.
if (this.hasBackdrop) {
this._backdropSubscription = this._overlayRef.backdropClick().subscribe(event => {
this.backdropClick.emit(event);
});
} else {
this._backdropSubscription.unsubscribe();
}
For some reason, this didn’t cause issues under Angular/CDK v8 but it causes issues in Ivy, presumably due to internal changes in Ivy’s change detector.
Environment
- Angular: 9.0.0-rc.14
- CDK/Material: 9.0.0-rc.9
- Browser(s): Chrome 79
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 10
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (3 by maintainers)
Top GitHub Comments
Issue still appearing with:
Angular: 9.1.9 CDK/Material: 9.2.4
This seems to be a more general problem. When you press the escape key, the overlay detaches, but the
detach
event doesn’t trigger change detection as well. Everything’s working fine, when youcdr.markForCheck()
in the handler.https://github.com/angular/components/blob/master/src/cdk/overlay/overlay-directives.ts#L287