ng-multiselect-dropdown
ng-multiselect-dropdown copied to clipboard
single select with nothing selected yet does not work
Angular version: latest
ng-multiselect-dropdown version:
Description of issue: used the single select version. When add of a new record. So there is nothing selected yet in the dropdown. When I then select something I get the next error:
"core.mjs:6362 ERROR TypeError: Cannot read properties of undefined (reading 'id')
at MultiSelectComponent.onItemClick (ng-multiselect-dropdown.mjs:169:51)
at MultiSelectComponent_li_13_Template_li_click_0_listener (ng-multiselect-dropdown.mjs:392:4901)
at executeListenerWithErrorHandling (core.mjs:14931:16)
at wrapListenerIn_markDirtyAndPreventDefault (core.mjs:14966:22)
at HTMLLIElement.
codeline in ng-multiselect-dropdown.mjs:
onItemClick($event, item) {
if (this.disabled || item.isDisabled) {
return false;
}
if (this._settings.singleSelection) {
if (item.id !== this.selectedItems[0].id) { ////this is the problem line, there is nothing in this.selectedItems yet. So first time select is not working !!!
this.addSelected(item);
}
}
else {
const found = this.isSelected(item);
console.log({ item, selectedItems: this.selectedItems });
const allowAdd = this._settings.limitSelection ==
Same issue here, seems like a bug with the latest version, to be fair it is labelled as beta, I downgraded it to [0.3.8] which solved the issue for me.
Yes! I downgraded to 0.3.8 and now it works! Thx