角度材料可折叠卡

cob*_*nks 7 angular-material angular-material2 angular

有没有办法用角形材料制作可折叠的卡片?看起来像是相当受欢迎的东西,但我一直在寻找合适的角度材料组件/设置:Angular Material - Card并没有发现任何东西.

谢谢!

mah*_*val 10

像Will提到的那样,只需使用扩展面板.https://material.angular.io/components/expansion/overview

否则只需创建一个普通的Angular Material卡并使用[hidden]质量或一些CSS(display:none)实现自己的折叠机制.您可以利用*ngIf和按钮事件来创建自己的可折叠卡片.不应该需要太多代码.

像这样的东西:

<mat-card>
  <mat-card-header>
     <mat-card-title style="font-size: 20px;">My collapsible card title</mat-card-title>
  </mat-card-header>

  <mat-card-content *ngIf="!collapsed">
    <p>This is some example text.</p>
     <p>This text will disappear when you use the action button in the actions bar below.</p>
  </mat-card-content>
  <mat-card-actions>
     <button mat-button (click)="collapsed=true">Collapse text</button>
     <button mat-button (click)="collapsed=false">Uncollapse text</button>
  </mat-card-actions>
</mat-card>
Run Code Online (Sandbox Code Playgroud)

Stackblitz:https://stackblitz.com/edit/angular-95ygrr


Tal*_*ziz 6

如果有人需要一个最新的“解决方案”与角料7,你可以把mat-expansion-panel里面mat-card-content并添加类mat-elevation-z0

<mat-card-content>
   <mat-expansion-panel class="mat-elevation-z0"> 
   ...
   </mat-expansion-panel>
</mat-card-content>
Run Code Online (Sandbox Code Playgroud)