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
The best answer is for clearing an input field on a specific action. I also use this code in my project according to my requirement.
In HTML write this code:
In .TS file add a ViewChild
for this control so that if your screen consists of multiple ngSelect
elements then you can clear a specific ngSelect
value.
@ViewChild('ngSelectComponent') ngSelectComponent: NgSelectComponent;
clearValue(){
this.ngSelectComponent.clearModel();
// This line will clear the value of ngSelect control.
// You can write code according to your requirement.
}