DevExtreme Angular - Handle the Value Change Event
By default, the value of the NumberBox is changed when the change event is raised. If you need the value to be changed on another event, set the valueChangeEvent option.
jQuery
$(function() { $("#numberBoxContainer").dxNumberBox({ value: 20, valueChangeEvent: 'keyup' }); });
Angular
<dx-number-box [value]="20" valueChangeEvent="keyup"> </dx-number-box>
import { DxNumberBoxModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxNumberBoxModule ], // ... })
To process a new NumberBox value, you need to handle the value change event. If the handling function is not going to be changed during the lifetime of the widget, assign it to the onValueChanged option when you configure the widget.
jQuery
$(function() { $("#numberBoxContainer").dxNumberBox({ onValueChanged: function (e) { var previousValue = e.previousValue; var newValue = e.value; // Event handling commands go here } }); });
Angular
<dx-number-box ... (onValueChanged)="numberBox_valueChanged($event)"> </dx-number-box>
import { DxNumberBoxModule } from "devextreme-angular"; // ... export class AppComponent { numberBox_valueChanged (e) { let previousValue = e.previousValue; let newValue = e.value; // Event handling commands go here } } @NgModule({ imports: [ // ... DxNumberBoxModule ], // ... })
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.
var valueChangedHandler1 = function (e) { var previousValue = e.previousValue; var newValue = e.value; // First handler of the "valueChanged" event }; var valueChangedHandler2 = function (e) { var previousValue = e.previousValue; var newValue = e.value; // Second handler of the "valueChanged" event }; $("#numberBoxContainer").dxNumberBox("instance") .on("valueChanged", valueChangedHandler1) .on("valueChanged", valueChangedHandler2);
See Also
- Handle Events: Angular | Vue | React | jQuery | AngularJS | Knockout | ASP.NET MVC 5 | ASP.NET Core
- NumberBox - Control the Behavior
- NumberBox Demos
- NumberBox API Reference
If you have technical questions, please create a support ticket in the DevExpress Support Center.