Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 离子3点击按钮后从离子文本区获取文本_Angular_Typescript_Ionic Framework_Textarea_Ionic3 - Fatal编程技术网

Angular 离子3点击按钮后从离子文本区获取文本

Angular 离子3点击按钮后从离子文本区获取文本,angular,typescript,ionic-framework,textarea,ionic3,Angular,Typescript,Ionic Framework,Textarea,Ionic3,我有一个离子文本区,用户可以在其中写入一些内容,我希望在单击按钮后获得此文本。 这是html: <ion-row> <ion-item> <ion-textarea [(ngModel)]="myInput" (ionInput)="getItems($event)" placeholder="New Info"></ion-textarea> </ion-item> </ion-row>

我有一个
离子文本区,用户可以在其中写入一些内容,我希望在单击按钮后获得此文本。
这是html:

<ion-row>
    <ion-item>
        <ion-textarea [(ngModel)]="myInput" (ionInput)="getItems($event)" placeholder="New Info"></ion-textarea>
    </ion-item>
</ion-row>

但它会打印“您编写了
未定义的
”。获取文本作为字符串并使用它的正确方法是什么?

既然您使用了双向数据绑定,您可以按如下所示进行操作

.html


尝试在getItems()方法中控制台.log(textarea)并查看值它不会打印任何内容甚至不会调用getItems()方法。尝试在addInfo()中使用ngModel“myInput”而不是this.textSearch
<button ion-button class="card-button" color="secondary" 
 (click)="addInfo()"> <ion-icon name="add-circle" class="icona-bottone"></ion-
 icon>Add Info</button>
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)
}
<ion-row>
    <ion-item>
        <ion-textarea [(ngModel)]="myInput" placeholder="New Info"></ion-textarea>
    </ion-item>
</ion-row>
console.log(this.myInput);//this is your textarea value