【发布时间】:2019-08-08 09:26:28
【问题描述】:
我已经在 ts 文件中导入了 ViewChild,ElementRef,Renderer 但它显示错误“ERROR TypeError: Cannot read property 'nativeElement' of undefined”
import { Component, OnInit,ViewChild,ElementRef,Renderer } from '@angular/core';
@ViewChild('usernameField') input : ElementRef;
this.usernameField.nativeElement.focusIn();
期望关注输入元素。
【问题讨论】:
-
也发布你的html
-
你的变量是
this.input,不是this.usernameField,函数是focus()不是focusIn()