Skip to content

Commit 8fabf01

Browse files
pkozlowski-opensourceandrewseguin
authored andcommitted
fix(autofill): use static queries to read values used in ngOnInit (#15574)
1 parent a18a195 commit 8fabf01

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/material-examples/text-field-autofill-monitor/text-field-autofill-monitor-example.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import {AutofillMonitor} from '@angular/cdk/text-field';
2-
import {Component, ElementRef, OnDestroy, OnInit, ViewChild} from '@angular/core';
2+
import {AfterViewInit, Component, ElementRef, OnDestroy, ViewChild} from '@angular/core';
33

44
/** @title Monitoring autofill state with AutofillMonitor */
55
@Component({
66
selector: 'text-field-autofill-monitor-example',
77
templateUrl: './text-field-autofill-monitor-example.html',
88
styleUrls: ['./text-field-autofill-monitor-example.css'],
99
})
10-
export class TextFieldAutofillMonitorExample implements OnDestroy, OnInit {
10+
export class TextFieldAutofillMonitorExample implements AfterViewInit, OnDestroy {
1111
@ViewChild('first', {read: ElementRef}) firstName: ElementRef<HTMLElement>;
1212
@ViewChild('last', {read: ElementRef}) lastName: ElementRef<HTMLElement>;
1313
firstNameAutofilled: boolean;
1414
lastNameAutofilled: boolean;
1515

1616
constructor(private autofill: AutofillMonitor) {}
1717

18-
ngOnInit() {
18+
ngAfterViewInit() {
1919
this.autofill.monitor(this.firstName)
2020
.subscribe(e => this.firstNameAutofilled = e.isAutofilled);
2121
this.autofill.monitor(this.lastName)

0 commit comments

Comments
 (0)