Hi,
I am currently working on dynamically creating a MultiSelectComponent and attempting to bind an event handler to it using a component API method. However, I'm encountering an error when using the addEventListener method.
Below is a sample code, and I am seeking assistance on how to correctly bind the event using the component API method.
https://stackblitz.com/edit/github-zlzkt9?file=src%2Fapp.component.ts
ngAfterViewInit(): void {
const ddlContainerDiv: HTMLElement = document.createElement('div');
this.ddlContainer!.element.nativeElement.appendChild(ddlContainerDiv);
const ddlInstance = new MultiSelectComponent(
this.ngEle,
this.sRenderer,
this.viewContainerRef,
this.injector,
this.cdr
);
ddlInstance.width = '200px';
ddlInstance.mode = 'CheckBox';
ddlInstance.showSelectAll = true;
ddlInstance.filterType = 'Contains';
ddlInstance.dataSource = this.dataSource!;
ddlInstance.query = this.query!;
ddlInstance.fields = { text: 'ContactName', value: 'CustomerID' };
try {
//Adding an EventListener for 'selectedAll' event thows an error ?
ddlInstance.addEventListener('selectedAll', (e: any) => {
console.log('On SelectedAll value:', e);
});
} catch (error) {
console.error('An error occurred:', error);
}
ddlInstance.registerOnChange((e) => {
console.log('OnChange value:', e);
});
ddlInstance.appendTo(ddlContainerDiv);
}
Regards,
Aruna