MCPcopy Create free account
hub / github.com/angular/components / _detachContentWhenEmpty

Method _detachContentWhenEmpty

src/cdk/overlay/overlay-ref.ts:523–553  ·  view source on GitHub ↗

Detaches the overlay once the content finishes animating and is removed from the DOM.

()

Source from the content-addressed store, hash-verified

521
522 /** Detaches the overlay once the content finishes animating and is removed from the DOM. */
523 private _detachContentWhenEmpty() {
524 let rethrow = false;
525 // Attempt to detach on the next render.
526 try {
527 this._detachContentAfterRenderRef = afterNextRender(
528 () => {
529 // Rethrow if we encounter an actual error detaching.
530 rethrow = true;
531 this._detachContent();
532 },
533 {
534 injector: this._injector,
535 },
536 );
537 } catch (e) {
538 if (rethrow) {
539 throw e;
540 }
541 // afterNextRender throws if the EnvironmentInjector is has already been destroyed.
542 // This may happen in tests that don't properly flush all async work.
543 // In order to avoid breaking those tests, we just detach immediately in this case.
544 this._detachContent();
545 }
546 // Otherwise wait until the content finishes animating out and detach.
547 if (globalThis.MutationObserver && this._pane) {
548 this._detachContentMutationObserver ||= new globalThis.MutationObserver(() => {
549 this._detachContent();
550 });
551 this._detachContentMutationObserver.observe(this._pane, {childList: true});
552 }
553 }
554
555 private _detachContent() {
556 // Needs a couple of checks for the pane and host, because

Callers 1

detachMethod · 0.95

Calls 2

_detachContentMethod · 0.95
observeMethod · 0.45

Tested by

no test coverage detected