Reputation: 129
I have used ng-select
to select multiple values from a list. As per requirement, the selected values should be shown below the ng-select
component, and it must be possible to remove the filter from below.
The code can be found here: https://stackblitz.com/edit/angular-gm6zrs?file=src/multi-select-default-example.component.ts
When I try to remove using the Remove button, though the item gets removed from ngModel - selectedPeople
here, it is not reflected in ng-select
.
Upvotes: 1
Views: 2818
Reputation: 771
Try add this code inside removeItem
function
this.selectedPeople = [...this.selectedPeople];
I've tried and it works, I also found this somewhere I forgot where it was so I can't give you an explanation
Upvotes: 1
Reputation: 9893
You can use filter
like that:
removeItem(idx) {
this.selectedPeople = this.selectedPeople.filter(t => t.name !== idx.name);
console.log(this.selectedPeople);
}
Here is working sample.
Upvotes: 0