Issue
I have an ion-textarea
in which user can write some content, and I would like to get this text after a button is clicked.
This is the 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>
I've tried doing this in my .ts file:
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)
}
but it prints "You wrote undefined
". What is the correct way to get the text as a string and use it?
Solution
Since you have used 2-way data bind you can do as shown below.
.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
Answered By - Sampath
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.