mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(autofill): use static queries to read values used in ngOnInit (#15516)
This commit is contained in:
committed by
Andrew Seguin
parent
e6af097acd
commit
345cd8c7d0
+3
-3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user