I’ve build a custom StencilJS component that fires a custom DOM event (see below). FYI: The ‘on’ part is added bij StencilJS itself.
@Event() searchEvent: EventEmitter<string>;
But when I want to bind to that event it doesn’t work. See my HTML and viewmodel.
// Html
<my-component ref="myComponent" search-event.trigger="handleSearch($event)">
// View model
export class App {
private myComponent: StencilJS.MyComponent;
private attached(): void {
// This works. So I know that the event is triggered properly.
this.myComponent.addEventListener('searchEvent', (ev: CustomEvent<string>) => this.handleSearch(ev));
}
private handleSearch(event: CustomEvent<string>): void {
// The event handler. This is not triggered via the 'search-event.trigger' binding.
}
}
But when I change the event name on my StencilJS component to the following
Thank you for the suggestion, it seems the gist is out of date, I tried the approach but without success.
There is error in the gist.
In addition tried it runs in my app but the trigger function is never called: