Search code examples
angulartypescriptmulti-selectangular-ngselect

ng-select remove the element in programmatic way in Angular 6


I am trying to remove the selected element from the ng-select using the program. As we can delete it using click cross button but we want to delete programmatic way in Angular 6. Please help me to find a perfect solution.

enter image description here


Solution

  • You want only this line :

    this.selectedCityIds = this.selectedCityIds.filter(s => s != id);
    

    Which is you can use it in your function in this way;

    deleteSingle (id: string) {
      this.selectedCityIds = this.selectedCityIds.filter(s => s != id);
    }