Is there any way in which I can expand a particular mat-expansion-panel by clicking an external button?
I have tried linking to the ID of the panel, but with no success...
<mat-expansion-panel id="panel1"> ... </>
...
<button (click)="document.getElementById('panel1').toggle()>Click me</button>
Here is my stackblitz code for example
My eventual plan is to use this method to open different panels within a list generated from an array: <mat-expansion-panel *ngFor="let d of data"> ...
In your html file:
In your TS file:
If you use *ngFor to generate the expansion panels:
If you press the button all of the expanded panels opens simultaneously.
To open only one panel with one button, add a "expanded" property to the data array for each element like this:
Then in your template:
And the method raised by the button click: