ng-multiselect-dropdown how to programmatically deselect

1.6k Views Asked by At

I have a dropdown that affects a second dependant dropdown. When the first is in a state of nothing selected, I want the dependant dropdown to also have whatever is selected deselected. Therefore I need to programmatically deselect the second dropdown.

I've got as far as resetting the selectedItems array to [] which clears the dropdown list. However, the previously selected items are still sitting in the bar where the placeholder text should ideally be restored. How can I do this?

1

There are 1 best solutions below

0
On BEST ANSWER

I finally solved this by resetting the form.

In my HTML component I gave it a form name: formControlName="multiselect"

In my typescript I had this @ViewChild('multiselect') multiSelect; and a method which did this: this.form.get("multiselect").setValue([]); and called it whenever I deselected in the first multiselect or selected a new option in the first multiselect.

Worked a treat!