diff --git a/src/aria/combobox/combobox-popup.ts b/src/aria/combobox/combobox-popup.ts index 8fc6263529bb..dcd3c70a86d2 100644 --- a/src/aria/combobox/combobox-popup.ts +++ b/src/aria/combobox/combobox-popup.ts @@ -35,6 +35,9 @@ import {COMBOBOX_POPUP} from './combobox-tokens'; export class ComboboxPopup implements OnInit, OnDestroy { private readonly _deferredContent = inject(DeferredContent); + /** The combobox that the popup is registered with. */ + private _registeredCombobox: Combobox | undefined; + /** The combobox that the popup belongs to. */ readonly combobox = input.required(); @@ -60,12 +63,13 @@ export class ComboboxPopup implements OnInit, OnDestroy { }); ngOnInit() { - this.combobox()._registerPopup(this); - this._deferredContent.deferredContentAware.set(this.combobox()); + this._registeredCombobox = this.combobox(); + this._registeredCombobox._registerPopup(this); + this._deferredContent.deferredContentAware.set(this._registeredCombobox); } ngOnDestroy() { - this.combobox()._unregisterPopup(); + this._registeredCombobox?._unregisterPopup(); } /** Registers a widget with the popup. */ diff --git a/src/aria/combobox/combobox.spec.ts b/src/aria/combobox/combobox.spec.ts index fb21bba8e71b..92df84078b94 100644 --- a/src/aria/combobox/combobox.spec.ts +++ b/src/aria/combobox/combobox.spec.ts @@ -1319,6 +1319,11 @@ describe('Combobox', () => { expect(comboboxElement.getAttribute('aria-expanded')).toBe('true'); }); }); + + it('should not throw when destroyed before the first change detection', () => { + const fixture = TestBed.createComponent(ComboboxListboxExample); + expect(() => fixture.destroy()).not.toThrow(); + }); }); @Component({