Is it possible to programmatically clear the selection of an ng-select dropdown? I\'m wanting the equivalent behaviour of clicking the clear icon, but triggered programmatically
Assuming the originally posted code sample below.
The selectedCalculation
variable is created as an array and not a string, as the ng-select can allow for multiple values to be selected if [multiple]="true"
is set.
To clear the selected value(s) in the array programmatically, use:
this.selectedCalculation = [];
Should you need to clear the bound items, use:
this.calculationOptions = [];
Both of the above can be done by adding the (change) handler in HTML.
(change)="change($event)
Something like this in your TypeScript.
change(event: any): void {
this.calculationOptions = [];
this.selectedCalculation = [];
}