Skip to content

Commit 3560d79

Browse files
committed
refactor(material/select): use afterNextRender to wait for options
1 parent 63a764d commit 3560d79

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/material/select/select.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ import {
6161
booleanAttribute,
6262
inject,
6363
numberAttribute,
64+
afterNextRender,
65+
Injector,
6466
} from '@angular/core';
6567
import {
6668
AbstractControl,
@@ -553,10 +555,17 @@ export class MatSelect
553555
);
554556
}
555557

556-
return this._ngZone.onStable.pipe(
557-
take(1),
558-
switchMap(() => this.optionSelectionChanges),
559-
);
558+
return new Observable(subscriber => {
559+
afterNextRender(
560+
() => {
561+
subscriber.next();
562+
subscriber.complete();
563+
},
564+
{
565+
injector: this._injector,
566+
},
567+
);
568+
}).pipe(switchMap(() => this.optionSelectionChanges));
560569
}) as Observable<MatOptionSelectionChange>;
561570

562571
/** Event emitted when the select panel has been toggled. */
@@ -584,10 +593,16 @@ export class MatSelect
584593
*/
585594
@Output() readonly valueChange: EventEmitter<any> = new EventEmitter<any>();
586595

596+
private _injector = inject(Injector);
597+
587598
constructor(
588599
protected _viewportRuler: ViewportRuler,
589600
protected _changeDetectorRef: ChangeDetectorRef,
590-
protected _ngZone: NgZone,
601+
/**
602+
* @deprecated Unused param, will be removed.
603+
* @breaking-change 19.0.0
604+
*/
605+
_unusedNgZone: NgZone,
591606
defaultErrorStateMatcher: ErrorStateMatcher,
592607
readonly _elementRef: ElementRef,
593608
@Optional() private _dir: Directionality,

tools/public_api_guard/material/select.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export { MatPrefix }
8686

8787
// @public (undocumented)
8888
export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit, DoCheck, ControlValueAccessor, MatFormFieldControl<any> {
89-
constructor(_viewportRuler: ViewportRuler, _changeDetectorRef: ChangeDetectorRef, _ngZone: NgZone, defaultErrorStateMatcher: ErrorStateMatcher, _elementRef: ElementRef, _dir: Directionality, parentForm: NgForm, parentFormGroup: FormGroupDirective, _parentFormField: MatFormField, ngControl: NgControl, tabIndex: string, scrollStrategyFactory: any, _liveAnnouncer: LiveAnnouncer, _defaultOptions?: MatSelectConfig | undefined);
89+
constructor(_viewportRuler: ViewportRuler, _changeDetectorRef: ChangeDetectorRef,
90+
_unusedNgZone: NgZone, defaultErrorStateMatcher: ErrorStateMatcher, _elementRef: ElementRef, _dir: Directionality, parentForm: NgForm, parentFormGroup: FormGroupDirective, _parentFormField: MatFormField, ngControl: NgControl, tabIndex: string, scrollStrategyFactory: any, _liveAnnouncer: LiveAnnouncer, _defaultOptions?: MatSelectConfig | undefined);
9091
ariaLabel: string;
9192
ariaLabelledby: string;
9293
protected _canOpen(): boolean;
@@ -153,8 +154,6 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
153154
ngOnDestroy(): void;
154155
// (undocumented)
155156
ngOnInit(): void;
156-
// (undocumented)
157-
protected _ngZone: NgZone;
158157
_onAttached(): void;
159158
_onBlur(): void;
160159
_onChange: (value: any) => void;

0 commit comments

Comments
 (0)