简体   繁体   English

Viewchild 为 null

[英]Viewchild is null

(Angular 9) I need to use ViewChield().This is my html: (Angular 9)我需要使用 ViewChield()。这是我的 html:

<input type="text" pInputText [(ngModel)]="code" #inputStudent/>

in my ts I do:在我的 ts 我做:

    @ViewChild('inputStudent', { read: ElementRef }) someInput: Input;
....

ngAfterViewChecked() {
    if (this.someInput != null) {
      console.log(this.someInput);
    } else {
      console.log("object null;");
    }

  }

the problem is that my ViewChild is null because console prints me "object null;"问题是我的 ViewChild 是 null 因为控制台打印我"object null;" .Anyone can help me? .任何人都可以帮助我吗?

@ViewChild("inputStudent",{ static:true}) someInput: ElementRef;
....
console.log(this.someInput.nativeElement.value);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM