Cannot read property 'native-element' of undefined

后端 未结 8 813
借酒劲吻你
借酒劲吻你 2020-12-09 02:34

I am using ionic 2.

I need to get HTML element value.

Actually, I used viewchild.

Here is my html template code

8条回答
  •  既然无缘
    2020-12-09 03:03

    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.

提交回复
热议问题