What is the Angular4 "Change" event trigger directive in Textarea
Asked Answered
E

2

39

Here is one of the versions that I tried INSIDE TEXTAREA: (change)="dosomething($event)"

and it's not doing anything. What is the directive for "change"?

Elliellicott answered 27/4, 2017 at 21:36 Comment(1)
check my answer belowArmanda
A
57

You should be using ngModelChange

   <textarea cols="25" [ngModel]="data" (ngModelChange)="doSomething($event)"></textarea>

LIVE DEMO

Update:

(change) event will work in textarea but it is triggered on blur and text changed inside the text area

DEMO

Armanda answered 27/4, 2017 at 21:42 Comment(4)
It does work with values. But how can I bind it with the $event? Why (change) is not working?Elliellicott
I see! Thanks a lotElliellicott
This worked. Thx. Unfortunately there couldn't be found any further documentation about this except than that at angular.io/guide/template-syntax.Selfdeception
(input)=doSomething($event) also seems to work for me. (I am using Angular 6.) Are they identical? If you only want the doSomething() method running in response to the user, should you use (input) instead of (ngModelChange) ?Goodrich
C
31

(change) didn't work for me neither, try (input) it worked perfectly :

<textarea [(ngModel)]="mytext" (input)="autoGrow($event)"></textarea>
Cid answered 9/2, 2019 at 23:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.