8

Can you nest Lists in Angular Material?

I haven't seen any examples in the documentation.

I guessed that I should use a multiline list, but I'm doing something wrong.

Things that I have tried.

2

2 Answers 2

32

As indicated by @Vega in the comments, you can't nest a <mat-list> under a <mat-list-item>, but if you ngFor another div that contains them both, it's still ok, and the <mat-list> line height is correct.

Here is an example by @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>
1

There is now an Angular Material "tree" component, which is basically a list of nested lists similar to a file structure. If that it what you are looking for you can find it here: https://material.angular.io/components/tree/overview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.