Does any one know how to programmatically open or close mat-select? As pert the api there are methods for open and close but don't know how to call those methods from component and there isn't any example showing that on site.
Thanks
Does any one know how to programmatically open or close mat-select? As pert the api there are methods for open and close but don't know how to call those methods from component and there isn't any example showing that on site.
Thanks
In order to access these properties you need to identify the DOM element and access it with a
ViewChild
:component.html
component.ts
View a working stackblitz here.
Another approach, so as not to so tightly couple the material component to your typescript code would be to handle this all on the HTML side.
I used
toggle()
on the "selected" answer to both open or close the panel, although you can substituteopen()
orclose()
calls depending on your needs.The key piece seems to be that template variable (
#mySelect
) that I learned thanks to the answer that @zbagley provided. I just kept tinkering to make it work without the tight binding of a@ViewChild
.Cheers, Dan