Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic text-area input event

I am using Ionic3, and have:

        <ion-textarea (change)="reviewChange()"></ion-textarea>

When a user changes the input, and blurs focus from the text area, the reviewChange() function is triggered as expected.

Question

Is it possible to add an equivalent of the ion-searchbar's ionInput event? i.e. when a user types text, an event is triggered for each key pressed.

Background

I am trying to track how many characters a user has left. e.g.

500 characters left

In order to do so, I need to track each key stroke. Unless there's a better way, or some automated way to do this?

like image 992
Richard Avatar asked Dec 07 '22 18:12

Richard


2 Answers

An easier way would be to bind the text area to a property from the component

<ion-textarea maxlength="500" [(ngModel)]="myText"></ion-textarea>

And below that text area you can show the characters left like this

<span>{{ 500 - myText.length }} characters left</span>
like image 186
sebaferreras Avatar answered Dec 10 '22 10:12

sebaferreras


You may simply try the (input) event. It fires for every key input.

     <ion-textarea [(ngModel)]="text" (input)="reviewChange()"></ion-textarea>
like image 24
Man Coding Avatar answered Dec 10 '22 11:12

Man Coding