ionic 3 单击按钮后从 ion-textarea 获取文本

ionic 3 get text from ion-textarea after clicking a button

我有一个 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)
}

但它打印 "You wrote undefined "。将文本作为字符串获取并使用它的正确方法是什么?

由于您使用了 2 向数据绑定,因此您可以按如下所示进行操作。

.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