HTML5 has an eventing mechanism that works for HTML elements, but cannot be used to add events to arbitrary objects, such as controls and collections.
Because of this, Wijmo defines an Event class that is used for implementing all events for all Wijmo classes. The main differences between Wijmo and HTML events are:
Wijmo events do not replace HTML events! Applications typically use both. HTML events are used to handle mouse and keyboard interactions that target a control's hostElement or elements defined in the control template. Wijmo events are used to handle control-specific events that are not directly related to the DOM. For example, valueChanged or rowAdded.
The example below shows how you can add handlers to HTML and Wijmo events on an InputNumber control using plain JavaScript:
import { InputNumber } from '@grapecity/wijmo.input';
// create the control
let ctl = new InputNumber('#inputNumber');
// attach a Wijmo event handler
ctl.valueChanged.addHandler(function (s, e) {
console.log('the value has changed to ' + s.value);
});
// attach an HTML event handler
ctl.addEventListener(ctl.hostElement, 'keypress', function(e) {
console.log('you pressed ' + e.charCode);
});
The example above shows the syntax using plain JavaScript. Applications that use frameworks such as Angular, React, Aurelia, or Vue have to use the syntax dictated by the framework.
For example, an Angular 1.x would attach a handler to the valueChanged Wijmo event this way:
<wj-input-number
value-changed="myValueChangedEventHander(s, e)">...
In Angular2, you would do this instead:
<wj-input-number #theControl
(value-changed)="myValueChangedEventHander(theControl, $event)">...