Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 material nested md-list-item

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

enter image description here

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

enter image description here

I want to achieve nested list, probably collapsible. Any idea what am i doing wrong or how to approach this ?

like image 721
Aishwat Singh Avatar asked Jun 05 '17 17:06

Aishwat Singh


1 Answers

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

enter image description here

Hope this helps someone, someday

like image 106
Aishwat Singh Avatar answered Sep 21 '22 15:09

Aishwat Singh