Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
no very sure, but around 18.2.x
Description
The overlay content has not been removed.
Reproduction
StackBlitz link:
Steps to reproduce:
- git clone https://github.com/keatkeat87/ng-mat-overlay-detach-issue.git
- ng serve
- click open and then close.
if use ZoneChangeDetection, then no problem.
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideAnimations()] // work
// providers: [provideExperimentalZonelessChangeDetection(), provideAnimations()] // no work
};
only ZonelessChangeDetection have the problem.
if we manual call detectChanges(), then it work.
export class ModalContainerComponent {
private readonly overlayRef = inject(OverlayRef);
private cdk = inject(ChangeDetectorRef);
close() {
this.overlayRef.detach();
this.cdk.detectChanges(); // manual detectChanges will work
// this.cdk.detectChanges(); // without detectChanges no work
}
}
Expected Behavior
The overlay content should be removed.
Actual Behavior
The overlay content has not been removed.
Environment
Angular CLI: 18.2.7
Node: 20.11.1
Package Manager: yarn 1.22.19
OS: win32 x64
Angular: 18.2.7
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
@angular-devkit/architect 0.1802.7
@angular-devkit/build-angular 18.2.7
@angular-devkit/core 18.2.7
@angular-devkit/schematics 18.2.7
@angular/cdk 18.2.6
@angular/material 18.2.6
@schematics/angular 18.2.7
rxjs 7.8.1
typescript 5.5.4
zone.js 0.14.10