Reputation: 903
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?
Upvotes: 0
Views: 2099
Reputation: 903
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!
Upvotes: 1