Set up dynamic menu

Asked

Viewed 345 times

0

I have the following array

inserir a descrição da imagem aqui

I would like to introduce a menu with a dynamic submenu, more or less like this one

inserir a descrição da imagem aqui

I tried to do it that way

<ul class="sidebar-menu" data-widget="tree" *ngIf="menuArray">
        <li class="header">MAIN NAVIGATION</li>

        <ng-container *ngFor="let menu of menuArray ">

            <li *ngIf="menu.submenu; else itemMenu" class="treeview">
              <a href="#">
                <i class="fa {{ menu.logo }}"></i><span>{{ menu.menu }}</span>
                <span class="pull-right-container">
                    <i class="fa fa-angle-left pull-right"></i>
                </span>
              </a>
            </li>
            <ng-template #itemMenu>
              <li>
                <a href="#">
                    <i class="fa {{ menu.logo }}"></i><span>{{ menu.menu }}</span>                               
                </a>
              </li>   
            </ng-template>
        </ng-container>
 </ul>

But is giving the following message on the console **

core.js:1673 ERROR Error: Error trying to diff '[Object Object]'. Only arrays and iterables are allowed

**

In my component I initialize my array

export class MenuComponent implements OnInit {
  menuArray = []
  constructor(private loginService: LoginService) {

   }

Then I take the data from the bank like this:

 getMenuArray(){
    this.loginService.menu( window.sessionStorage.getItem('id') )
                     .subscribe( menu => {
                       this.menuArray = menu
                       console.log('menu', menu)

                      }) 

  }

Or there’s how I set up the menu on Component.ts and then play on the page?

1 answer

1


  • 1

    Didn’t it start to work? In my component I changed it this.menuArray = menu for that reason this.menuArray = menu.array and appeared the menus, now I will work on the submenus

Browser other questions tagged

You are not signed in. Login or sign up in order to post.