Using Angular 2 with material design, trying to get nested lists in sidenav I have code like
<md-sidenav #sidenav class="sidenav" mode="over" opened>
<md-nav-list>
<md-card class="user-card">
<md-card-header>
<div md-card-avatar class="user-avatar"></div>
</md-card-header>
</md-card>
<md-divider></md-divider>
<md-list-item *ngFor="let category of ategories">
<a md-line>{{ category.name }}</a>
</md-list-item>
</md-nav-list>
</md-sidenav>
which works fine and looks something like
Now When i try to nest it, like
<md-sidenav #sidenav class="sidenav" mode="over" opened>
<md-nav-list>
<md-card class="user-card">
<md-card-header>
<div md-card-avatar class="user-avatar"></div>
</md-card-header>
</md-card>
<md-divider></md-divider>
<md-list-item *ngFor="let category of ategories">
<a md-line>{{ category.name }}</a>
<md-list-item *ngFor="let subcategory of category.subcategories">
<a md-line>{{ subcategory.subcategory }}</a>
</md-list-item>
</md-list-item>
</md-nav-list>
</md-sidenav>
It appears like
I want to achieve nested list, probably collapsible. Any idea what am i doing wrong or how to approach this ?
Ok, figured it out, if someone in future gets stuck like this.
Do no *ngfor
on md-list-item
, rather do it on div
, like this
<md-list>
<div *ngFor="let category of practice_categories">
<md-list-item>{{category.category}}</md-list-item>
<md-list style="margin-left:30px;">
<div *ngFor="let subcategory of category.subcategories">
<md-list-item>{{ subcategory.subcategory }}</md-list-item>
</div>
</md-list>
</div>
</md-list>
which produces something like
Hope this helps someone, someday
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With