Repository navigation
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
Activity
crisbeto commentedon Oct 4, 2024
This looks like a framework issue. The combination of zoneless and one of the animations modules (either enabled or noop) prevents the element from being removed until the next change detection. I've isolated it in the following Stackblitz: https://stackblitz.com/edit/stackblitz-starters-9p2rdd?file=src%2Fmain.ts
[-]bug(Overlay): OverlayRef.detach not working when using ZonelessChangeDetection (v18.2.6)[/-][+]Dynamically-created component not removed when zoneless is combined with animations[/+]fix(core): Flush animations when no component has been checked (angul…
angular-automatic-lock-bot commentedon May 10, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.