fix(autofill): use static queries to read values used in ngOnInit (#15516)

This commit is contained in:
Pawel Kozlowski
2019-03-22 18:45:14 +01:00
committed by Andrew Seguin
parent e6af097acd
commit 345cd8c7d0
@@ -1,5 +1,5 @@
import {AutofillMonitor} from '@angular/cdk/text-field';
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {AfterViewInit, Component, ElementRef, OnDestroy, ViewChild} from '@angular/core';
/** @title Monitoring autofill state with AutofillMonitor */
@Component({
@@ -7,7 +7,7 @@ import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core
templateUrl: './text-field-autofill-monitor-example.html',
styleUrls: ['./text-field-autofill-monitor-example.css'],
})
export class TextFieldAutofillMonitorExample implements OnDestroy, OnInit {
export class TextFieldAutofillMonitorExample implements AfterViewInit, OnDestroy {
@ViewChild('first', {read: ElementRef}) firstName: ElementRef<HTMLElement>;
@ViewChild('last', {read: ElementRef}) lastName: ElementRef<HTMLElement>;
firstNameAutofilled: boolean;
@@ -15,7 +15,7 @@ export class TextFieldAutofillMonitorExample implements OnDestroy, OnInit {
constructor(private autofill: AutofillMonitor) {}
ngOnInit() {
ngAfterViewInit() {
this.autofill.monitor(this.firstName)
.subscribe(e => this.firstNameAutofilled = e.isAutofilled);
this.autofill.monitor(this.lastName)