我想在垫子扩展面板标题展开时更改它的内容,当它折叠时返回到先前的状态。
<mat-expansion-panel>
<mat-expansion-panel-header>
<div>{{'my name is joe'}}</div>
<div>{{'i am 20 years old'}}</div>
// when expanded i want to hide the second div and change
// the style of first div margin, padding e.t.c
</mat-expansion-panel-header>
// ....
</mat-expansion-panel>
答案 0 :(得分:2)
您可以像这样使用模板变量和expanded
的属性mat-expansion-panel
:
模板
<mat-expansion-panel #panel>
<mat-expansion-panel-header>
<div [ngClass]="{'first-div': panel.expanded}">Always shown</div>
<div *ngIf="!panel.expanded">Not shown when expanded</div>
</mat-expansion-panel-header>
Content here
</mat-expansion-panel>
CSS
.first-div {
background-color: red;
}
更新后的stackblitz会在展开时隐藏第二个div
并将CSS类应用于第一个。