我正在使用离子2.
@H_403_2@我需要获得htmlelement值.
@H_403_2@我实际上使用了viewchild.
@H_403_2@这是我的html模板代码
<div class="messagesholder" *ngFor="let chat of chatval | orderby:'[date]'; let last = last"> {{last ? callFunction() : ''}} <div *ngIf="chat.sender == currentuser || chat.receiver == currentuser"> <p class="chat-date" id="abc" #abc>{{chat.date | amDateFormat:'LL'}}</p> {{checkdate()}} </div>@H_403_2@chat.date值是firebase值.我访问这个元素.但我没有得到元素的价值. @H_403_2@这是我的组件
import {Component,ElementRef,ViewChild,OnInit} from '@angular/core'; export class ChatPage { @ViewChild(Content) content: Content; @ViewChild('abc')abc: ElementRef; constructor(){} ngAfterViewInit(){ console.log("afterinit"); console.log(this.abc.nativeElement.value); } }@H_403_2@我把这个链接称为How can I select an element in a component template? @H_403_2@我尝试了很多方式. @H_403_2@但我得到这个错误
Cannot read property 'nativeElement' of undefined.