From 4af27f5d12047c16693d893769cdcfc86e483687 Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Mon, 22 Apr 2019 15:38:45 -0700 Subject: [PATCH] fix(autocomplete): make template ViewChild query `static: true` 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. --- src/lib/autocomplete/autocomplete.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/autocomplete/autocomplete.ts b/src/lib/autocomplete/autocomplete.ts index 1a032d0ca279..f641309d78d7 100644 --- a/src/lib/autocomplete/autocomplete.ts +++ b/src/lib/autocomplete/autocomplete.ts @@ -104,8 +104,12 @@ export class MatAutocomplete extends _MatAutocompleteMixinBase implements AfterC get isOpen(): boolean { return this._isOpen && this.showPanel; } _isOpen: boolean = false; + // 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. + /** @docs-private */ - @ViewChild(TemplateRef, {static: false}) template: TemplateRef; + @ViewChild(TemplateRef, {static: true}) template: TemplateRef; /** Element for the panel containing the autocomplete options. */ @ViewChild('panel', {static: false}) panel: ElementRef;