首页 > 解决方案 > 角度材料中的嵌套列表

问题描述

你可以在 Angular Material 中嵌套列表吗?

我没有在文档中看到任何示例

我猜我应该使用多行列表,但我做错了。

我尝试过的事情。

标签: angularangular-material2

解决方案


正如评论中@Vega所指出的,您不能在 a<mat-list>下嵌套 a <mat-list-item>,但是如果您 ngFor 另一个包含它们的 div ,它仍然可以,并且<mat-list>行高是正确的。

这是@Vega的一个示例:https ://stackblitz.com/edit/angular-nnkg3h-xppmzz

<mat-list>
    <ng-container *ngFor="let item of items">
        <mat-list-item>{{item.name}}</mat-list-item>
        <mat-list style="margin-left:30px;">
            <div *ngFor="let subItem of item.subItems">
                <mat-list-item>{{ subItem.name }}</mat-list-item>
            </div>
        </mat-list>
    </ng-container>
</mat-list>

推荐阅读