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
  • Btw I've seen this question, it's for an older version of the framework. Commented Apr 27, 2018 at 21:56
  • 2
    So you have the answer? stackblitz.com/edit/angular-nnkg3h-xppmzz Commented Apr 28, 2018 at 7:26

2 Answers 2

35

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>
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.