I can't seem to figure out how to change different booleans when I select an item out of the NG Multiselect dropdown list.
in my app.component.ts
ngOnInit() {
this.dropdownList = [
{ item_id: 1, item_text: 'option 1' },
{ item_id: 2, item_text: 'option 2'},
{ item_id: 3, item_text: 'option 3'},
{ item_id: 4, item_text: 'etc' },
{ item_id: 5, item_text: 'etc' }
];
this.dropdownSettings = {
singleSelection: false,
idField: 'item_id',
textField: 'item_text',
selectAllText: 'Selecteer allemaal',
unSelectAllText: 'Verwijder selectie',
itemsShowLimit: 3,
allowSearchFilter: true
};
}
onItemSelect(item: any) {
console.log(item);
}
onSelectAll(items: any) {
console.log(items);
}
}
Above code works fine. When I select an item it gets logged in the console
What I am aiming to achieve is when item_id 1 is checked, set a boolean to true. Something like this (but does not work):
onItemSelect(item: any) {
if(this.dropdownList.idField == 1) {
this.option1boolean = true
}
if (this.dropdownList.idField == 2) {
this.option2boolean = true
}
}
Thanks in advance
CodePudding user response:
use item.item_id in place of this.dropdownList.idField
public onItemSelect(item: any) {
if (item.item_id === 1) {
this.option1boolean = true;
}
if (item.item_id === 2) {
this.option2boolean = true;
}
}