(Angular 9)我需要使用ViewChield().This是我的html:
<input type="text" pInputText [(ngModel)]="code" #inputStudent/>在我的测试中,我这样做:
@ViewChild('inputStudent', { read: ElementRef }) someInput: Input;
....
ngAfterViewChecked() {
if (this.someInput != null) {
console.log(this.someInput);
} else {
console.log("object null;");
}
}问题是我的ViewChild是空的,因为控制台打印我"object null;".Anyone可以帮助我吗?
发布于 2020-07-16 16:25:15
@ViewChild("inputStudent",{ static:true}) someInput: ElementRef;
....
console.log(this.someInput.nativeElement.value);https://stackoverflow.com/questions/62930146
复制相似问题