Angular TextArea - Handle the Value Change Event

When a user types a text into the TextArea, the UI component writes this text into the value property when the change event is raised. If you need this to happen on another event, set the valueChangeEvent property.

HTML
TypeScript
  • <dx-text-area
  • valueChangeEvent="keyup">
  • </dx-text-area>
  • import { DxTextAreaModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • // ...
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxTextAreaModule
  • ],
  • // ...
  • })

To process a new TextArea value, you need to handle the value change event. If the handling function is not going to be changed during the lifetime of the UI component, assign it to the onValueChanged property when you configure the UI component.

HTML
TypeScript
  • <dx-text-area
  • [(value)]="textAreaValue"
  • (onValueChanged)="handleValueChange($event)">
  • </dx-text-area>
  • import { DxTextAreaModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • textAreaValue = "The TextArea value";
  •  
  • handleValueChange(e) {
  • const previousValue = e.previousValue;
  • const newValue = e.value;
  • // Event handling commands go here
  • }
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxTextAreaModule
  • ],
  • // ...
  • })

If you are going to change event handlers at runtime, or if you need to attach several handlers to the value change event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
  • const valueChangedHandler1 = function (e) {
  • const previousValue = e.previousValue;
  • const newValue = e.value;
  • // First handler of the "valueChanged" event
  • };
  •  
  • const valueChangedHandler2 = function (e) {
  • const previousValue = e.previousValue;
  • const newValue = e.value;
  • // Second handler of the "valueChanged" event
  • };
  •  
  • $("#textAreaContainer").dxTextArea("instance")
  • .on("valueChanged", valueChangedHandler1)
  • .on("valueChanged", valueChangedHandler2);
See Also