Several ways you can do this, here's a couple examples:
Using @bindable
my-component.js
import {bindable} from 'aurelia-framework';
export class MyComponent {
@bindable change;
notifyChange() {
this.change({ someArg: 'something', anotherArg: 'hello' });
}
}
app.html
<template>
...
<my-component change.call="handleChange(someArg, anotherArg)"></my-component>
...
</template>
app.js
export class App {
handleChange(a, b) {
...
}
}
Using DOM events
my-component.js
import {inject} from 'aurelia-framework';
import {DOM} from 'aurelia-pal';
@inject(Element)
export class MyComponent {
constructor(element) {
this.element = element;
}
notifyChange() {
let detail = { someArg: 'something', anotherArg: 'hello' };
let eventInit = { detail, bubbles: true };
let event = DOM.createCustomEvent('change', eventInit);
this.element.dispatchEvent(event);
}
}
note: DOM.createCustomEvent is not required. Use new CustomEvent(...) if you do not want to abstract away the DOM for testing purposes or otherwise.
app.html
<template>
...
<my-component change.delegate="handleChange($event)"></my-component>
...
</template>
app.js
export class App {
handleChange(event) {
...
}
}