我有一个ion-textarea
,用户可以在里面写一些内容,我想在点击一个按钮后得到这个文本。
这是 html:
<ion-row>
<ion-item>
<ion-textarea [(ngModel)]="myInput" (ionInput)="getItems($event)" placeholder="New Info"></ion-textarea>
</ion-item>
</ion-row>
<button ion-button class="card-button" color="secondary"
(click)="addInfo()"> <ion-icon name="add-circle" class="icona-bottone"></ion-
icon>Add Info</button>
我已经尝试在我的 .ts 文件中这样做:
getItems(textarea) {
// set q to the value of the textarea
var q = textarea.srcElement.value;
this.textSearch = q;
}
addInfo(){
console.log("You wrote " + this.textSearch)
}
但它打印出“你写了undefined
”。将文本作为字符串获取并使用它的正确方法是什么?
最佳答案
由于您使用了 2 向数据绑定(bind),因此您可以执行如下所示的操作。
.html
<ion-row>
<ion-item>
<ion-textarea [(ngModel)]="myInput" placeholder="New Info"></ion-textarea>
</ion-item>
</ion-row>
.ts
console.log(this.myInput);//this is your textarea value
关于angular - ionic 3 单击按钮后从 ion-textarea 获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47679723/