Hi,
I want to add some items in a listbox programmatically in the way provided in the docs, but the call to getInstance fails with this error :
ERROR TypeError: Cannot read properties of null (reading 'ej2_instances')at getInstance (ej2-base.es5.js:450:13)
This is the code:
import { ListBox } from '@syncfusion/ej2-dropdowns';
let listboxobj:ListBox = getInstance(document.getElementById("listbox")!, ListBox) as ListBox;
listboxobj?.addItems(
rowData.idList.map((itemId: string) => {
return {
id: itemId,
text: this.listboxSource.find(item => item.id === itemId)?.name
}
}));
<ejs-listbox #listbox
id="listbox"
height="290px"
[toolbarSettings]="toolbar2"
name="listbox1"
formControlName="listbox1">
</ejs-listbox>
I also tried to reference the listbox by ViewChild, but it looks like the listBoxObj1 is not initialized, is always undefined:
import { CheckBoxSelectionService, ListBoxComponent } from '@syncfusion/ej2-angular-dropdowns';
@ViewChild('listbox') listboxObj1!: ListBoxComponent;
this.listboxObj1?.addItems(
rowData.idList.map((itemId: string) => {
return {
id: itemId,
text: this.listboxSource.find(item => item.id === itemId)?.name
}
}));
<ejs-listbox #listbox
id="listbox"
height="290px"
[toolbarSettings]="toolbar2"
name="listbox1"
formControlName="listbox1">
</ejs-listbox>
Any ideas how to solve this?