valor-software / ng2-select

Angular based replacement for select boxes
http://valor-software.github.io/ng2-select/
MIT License
676 stars 588 forks source link

How can I clear the value of a select? #955

Open wautersj opened 6 years ago

wautersj commented 6 years ago

I want to programatically clear the select and reset it in its original state. But am unable to do so.

I have tried to set the ngModel property to null, but this only works once. After resetting it a second time, the dropdown renders "undefined".

<iq-select2 #documentSearch css="form-control input-sm"
  [dataSourceProvider]="listDocuments"
  [iqSelect2ItemAdapter]="adapter"
  [selectedProvider]=""
  [placeholder]="placeholder"
  referenceMode="entity"
  (onSelect)="fileSelected($event)"
  (onRemove)="fileRemoved($event)"
  [(ngModel)]="selectedDocument"
  >

In code, I call this:

this.selectedDocument = null;

screen shot 2018-05-22 at 01 33 29

Help would be much appreciated!