File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ import {COMBOBOX_POPUP} from './combobox-tokens';
3535export class ComboboxPopup implements OnInit , OnDestroy {
3636 private readonly _deferredContent = inject ( DeferredContent ) ;
3737
38+ /** The combobox that the popup is registered with. */
39+ private _registeredCombobox : Combobox | undefined ;
40+
3841 /** The combobox that the popup belongs to. */
3942 readonly combobox = input . required < Combobox > ( ) ;
4043
@@ -60,12 +63,13 @@ export class ComboboxPopup implements OnInit, OnDestroy {
6063 } ) ;
6164
6265 ngOnInit ( ) {
63- this . combobox ( ) . _registerPopup ( this ) ;
64- this . _deferredContent . deferredContentAware . set ( this . combobox ( ) ) ;
66+ this . _registeredCombobox = this . combobox ( ) ;
67+ this . _registeredCombobox . _registerPopup ( this ) ;
68+ this . _deferredContent . deferredContentAware . set ( this . _registeredCombobox ) ;
6569 }
6670
6771 ngOnDestroy ( ) {
68- this . combobox ( ) . _unregisterPopup ( ) ;
72+ this . _registeredCombobox ? ._unregisterPopup ( ) ;
6973 }
7074
7175 /** Registers a widget with the popup. */
Original file line number Diff line number Diff line change @@ -1319,6 +1319,11 @@ describe('Combobox', () => {
13191319 expect ( comboboxElement . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
13201320 } ) ;
13211321 } ) ;
1322+
1323+ it ( 'should not throw when destroyed before the first change detection' , ( ) => {
1324+ const fixture = TestBed . createComponent ( ComboboxListboxExample ) ;
1325+ expect ( ( ) => fixture . destroy ( ) ) . not . toThrow ( ) ;
1326+ } ) ;
13221327} ) ;
13231328
13241329@Component ( {
You can’t perform that action at this time.
0 commit comments