且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法读取未定义的属性“nativeElement”

更新时间:2023-11-09 15:02:52

我认为你要从html获取价值在完全渲染之前。如果您尝试在按钮单击中打印该值,它将起作用。

I think you are tring to get the value from html before rendering completely. If you try to print the value in a button click, it will works.

取决于您的代码我已经修改了一点。试试下面,它对我有用。

depend on your code I have modified a little.Try the below, it is working for me.

  ngAfterViewInit() {
    console.log("afterinit");
    setTimeout(() => {
      console.log(this.abc.nativeElement.innerText);
    }, 1000);
  }

注意:如果不能正常工作,请增加超时时间再试一次。

Note: If not working, please increase the timeout time and try again.