Skip to content

Commit 388baa2

Browse files
authored
fix(autocomplete): make template ViewChild query static: true (#15877)
The `@ViewChild` query for TemplateRef here needs to be static because some code paths lead to the overlay being created before change detection has finished for this component. Notably, another component may trigger `focus` on the autocomplete-trigger.
1 parent b7f064b commit 388baa2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib/autocomplete/autocomplete.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterC
104104
get isOpen(): boolean { return this._isOpen && this.showPanel; }
105105
_isOpen: boolean = false;
106106

107+
// The @ViewChild query for TemplateRef here needs to be static because some code paths
108+
// lead to the overlay being created before change detection has finished for this component.
109+
// Notably, another component may trigger `focus` on the autocomplete-trigger.
110+
107111
/** @docs-private */
108-
@ViewChild(TemplateRef, {static: false}) template: TemplateRef<any>;
112+
@ViewChild(TemplateRef, {static: true}) template: TemplateRef<any>;
109113

110114
/** Element for the panel containing the autocomplete options. */
111115
@ViewChild('panel', {static: false}) panel: ElementRef;

0 commit comments

Comments
 (0)