Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Angular4 "Change" event trigger directive in Textarea

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"?

like image 471
Pano Avatar asked Apr 27 '17 21:04

Pano


People also ask

What is the difference between NgModelChange and change?

ngModelChange It fires when the model changes. You cannot use this event without ngModel directive. change triggers when the user changes the input. ngModelChange triggers when the model changes, irrespective of that change is caused by the user or not.

What is NgModelChange event in angular?

NgModelChange is an Angular specific event, which we can use to listen for changes to the user input. It is the @Output property of the ngModel directive, Hence we need to use it along with it. ngModle raises the NgModelChange event, whenever the model changes.

What is textarea in angular?

They provide data-binding, which means they are part of the AngularJS model, and can be referred to, and updated, both in AngularJS functions and in the DOM. They provide validation. Example: an <textarea> element with a required attribute, has the $valid state set to false as long as it is empty.


2 Answers

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

like image 153
Aravind Avatar answered Oct 11 '22 01:10

Aravind


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

<textarea [(ngModel)]="mytext" (input)="autoGrow($event)"></textarea> 
like image 44
Chtiwi Malek Avatar answered Oct 11 '22 03:10

Chtiwi Malek