【发布时间】:2018-05-20 15:43:15
【问题描述】:
我有一个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”。将文本作为字符串获取并使用它的正确方法是什么?
【问题讨论】:
-
尝试在 getItems() 方法中使用 console.log(textarea) 并查看值
-
它不打印任何东西
-
那么你的 getItems() 方法甚至不会被调用。尝试在 addInfo() 中使用 ngModel "myInput" 而不是 this.textSearch
标签: angular typescript ionic-framework textarea ionic3