Reputation: 15940
I am implementing the Expansion panel and collapsable panel. Here is my code on stackblitz.
<tr mat-row *matRowDef="let element; columns: columnsToDisplay;"
class="example-element-row"
[class.example-expanded-row]="expandedElement === element"
(click)="expandedElement = element">
</tr>
It is working except, when I click for first time, the expansion panel is opening and when I click second time, it should get collapsed, but it's not happening.
I found this example (see "Table with expandable rows" section) in official docs which works. A working example. Why is collapsible panel not working when clicked second time in my code?
Upvotes: 0
Views: 159
Reputation: 19813
(click)="expandedElement = element">
You should set expandedElement
to null
when you click on the same element:
<tr mat-row *matRowDef="let element; columns: columnsToDisplay;"
// ...
(click)="expandedElement = expandedElement === element ? null : element">
</tr>
Upvotes: 1