angular - Menu and submenu generation issue -


i created small project, menus , it's sub menus generated services. sub menus loading first time when main menu clicked, next time, doesn't load.

app.component.html:

<li class="treeview" *ngfor="let menu of menus">      <a href="#" *ngif="menu.parentmenuid === 0">         <i class="fa fa-book"></i> <span>{{menu.menu}}</span>         <span class="pull-right-container">            <i class="fa fa-angle-left pull-right"></i>         </span>      </a>      <ul class="treeview-menu" *ngfor="let submenu of menus">          <li *ngif="submenu.parentmenuid === menu.id"><a routerlink="{{submenu.htmlid}}"><i class="fa fa-circle-o"></i> {{submenu.menu}}</a></li>      </ul> </li> 

app.component.ts:

import { menuservice } './services/menu.service'; ... export class appcomponent {   menus: any;   constructor(_menuservice: menuservice) {     _menuservice.getmenu().subscribe(menus => this.menus = menus);     console.log(this.menus);   } } 

menu.service.ts:

import { injectable } '@angular/core'; import { http } '@angular/http'; import 'rxjs/add/operator/map';  import { global } '../app.globals';  @injectable() export class menuservice {    constructor(private http: http) { }    _data: any;    getmenu() {     return this.http       .get(global.base_api_url+'/api/menus/get/all')       .map(x => x.json())   } } 

and json is

[   {     "menu": "master",     "parentmenuid": 0,     "htmlid": "master",     "id": 1,     "code": null,     "isactive": true,     "enteredby": 0,     "entereddate": null,     "updatedby": null,     "updateddate": null   },   {     "menu": "entity",     "parentmenuid": 1,     "htmlid": "entity",     "id": 2,     "code": null,     "isactive": true,     "enteredby": 0,     "entereddate": null,     "updatedby": null,     "updateddate": null   },   {     "menu": "entries",     "parentmenuid": 0,     "htmlid": "entries",     "id": 3,     "code": null,     "isactive": true,     "enteredby": 0,     "entereddate": null,     "updatedby": null,     "updateddate": null   },   {     "menu": "register",     "parentmenuid": 3,     "htmlid": "register",     "id": 4,     "code": null,     "isactive": true,     "enteredby": 0,     "entereddate": null,     "updatedby": null,     "updateddate": null   },   {     "menu": "patient",     "parentmenuid": 3,     "htmlid": "patient",     "id": 5,     "code": null,     "isactive": true,     "enteredby": 0,     "entereddate": null,     "updatedby": null,     "updateddate": null   } ] 

here issue:

enter image description here

any advice helpful. thank you.

i think there other problem in code because menuservice instance should generated once in lifecycle only, if generated again null first of edit constructor(private _menuservice: menuservice) although not exact problem can dig via console.log in constructor of menuservice singleton


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -