hanik
hanik

Reputation: 129

Remove values selected in ng-select from outside

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

Answers (2)

naoval luthfi
naoval luthfi

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

Alireza Ahmadi
Alireza Ahmadi

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

Related Questions