Angular 2获取Input元素值
发布时间:2020-12-17 07:19:40 所属栏目:安全 来源:网络整理
导读:如何使用离子2获取html元素值 在我的HTML代码下面 div class="messagesholder" *ngFor="let chat of chatval | orderby:'[date]'" div *ngIf="chat.sender == currentuser || chat.receiver == currentuser" div *ngIf="chat.date" style="text-align: cente
|
如何使用离子2获取html元素值
在我的HTML代码下面 <div class="messagesholder" *ngFor="let chat of chatval | orderby:'[date]'" >
<div *ngIf="chat.sender == currentuser || chat.receiver == currentuser">
<div *ngIf="chat.date" style="text-align: center;" >
<p style="font-size:9px;" id="amount" #amount>{{chat.date | amDateFormat:'LL'}}</p>
<input #myname [ngModel]="range" (ngModelChange)="saverange($event)"/>
<input #myname type="text" value={{chat.date}}>
</div>
</div>
<div class="message" *ngIf="chat.sender == currentuser || chat.receiver == currentuser" [ngClass]="{'me': currentuser == chat.sender}">
<div class='image' *ngIf="chat.path" >
<img *ngIf="chat.path" [src]="chat.path"/><br>
<span *ngIf="chat.path_text">{{chat.path_text}}</span>
<span style="font-size:9px;">{{chat.date | amDateFormat:'hh:mmA'}}</span>
</div>
<div *ngIf="chat.message_text">
<span>{{chat.message_text}}</span>
<span style="font-size:9px;">{{chat.date | amDateFormat:'hh:mmA'}}</span>
</div>
</div>
在我的ts文件下面 import { Component,Inject,ViewChild,ElementRef,AfterViewInit} from '@angular/core';
export class ChatPage implements AfterViewInit {
@ViewChild('myname') input:ElementRef;
constructor(public modalCtrl: ModalController,public navCtrl: NavController) {}
ngAfterViewInit() {
console.log(this.input.nativeElement.value);
}
}
重复相同的日期值.我希望不重复相同的日期值. 因为我会检查两个变量. 所以我需要chat.date值.因为我绑定了input的值.但是我无法获得input元素的值. 我收到这个错误 无法读取未定义的属性“nativeElement” 如何解决这个问题.或任何其他方式来找到slutions. 谢谢
我创建了一个plnkr链接:
https://plnkr.co/edit/49TEP8lB4lNJEKsy3IDq?p=preview
它对我有用,所以你可能想要创建自己的plnkr,所以ppl可以提供帮助 export class ApiDemoApp{
root = ApiDemoPage;
@ViewChild('myname') input:ElementRef;
constructor() {
}
ngAfterViewInit() {
console.log(this.input.nativeElement.value);
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
