我使用材质列表控件来显示嵌套对象。我用div创建了mat列表,但我想在这里添加展开/折叠行选项,当我单击行时,它应该显示子类别div?
<mat-list>
<div *ngFor="let item of chaptersItems">
<mat-list-item>
<a style="cursor: pointer;">
<h4 mat-line>{{item.name}} {{item.description}}</h4>
</a>
</mat-list-item>
<mat-list style="margin-left:30px;">
<div *ngFor="let subItem of item.subChapters">
<mat-list-item>
<a style="cursor: pointer;">
<p mat-line> {{subItem.name}}. {{subItem.description}}</p>
</a>
</mat-list-item>
</div>
</mat-list>
</div>
</mat-list>如何在div或mat-list控件上实现点击功能?
发布于 2018-02-08 23:00:39
您可以将每个项目包装到mat-expansion-panel包装器中,如下所述:https://material.angular.io/components/expansion/overview
它看起来是这样的:
<mat-list>
<div *ngFor="let item of chaptersItems">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-list-item>
<a style="cursor: pointer;">
<h4 mat-line>{{item.name}} {{item.description}}</h4>
</a>
</mat-list-item>
<mat-expansion-panel-header>
<mat-list style="margin-left:30px;">
<div *ngFor="let subItem of item.subChapters">
<mat-list-item>
<a style="cursor: pointer;">
<p mat-line> {{subItem.name}}. {{subItem.description}}</p>
</a>
</mat-list-item>
</div>
</mat-list>
</mat-expansion-panel>
</div>
</mat-list>发布于 2018-02-08 22:26:41
您可以使用Expansion组件,它非常简单
https://stackoverflow.com/questions/48687758
复制相似问题