Page 2 of 2

Re: Dynamic items in menu

Posted: 05 Jan 2018, 00:03
by tbegsr
Hi
I try to create a dynamic menu, but I'm not able.
I've always the same status at the point I start the application
Can you give me more information and create an example please

Thx
Rolf

Re: Dynamic items in menu

Posted: 05 Jan 2018, 02:21
by paulswan
@tbegsr,
There are already 2 examples you can follow in this topic so I don't see how posting another will help. Basically you need to change the model object that the menu is using or Angular will not detect the change. If you are setting the visible property of a menu item to be a Boolean variable and then changing the value of the variable, then this will not work as the model itself has not changed and therefor will not be detected.

Re: Dynamic items in menu

Posted: 05 Jan 2018, 12:59
by tbegsr
@paulswan
Thank you for response
I've seen your example and try to implement it but I was not able
Can you tell me from which class you execute showHideMenuItems(roleID: number):
Many thanks in advanced

Re: Dynamic items in menu

Posted: 07 Jan 2018, 23:17
by paulswan
@tbegsr,
I actually created a MenuService class for the showHideMenuItems() function as this allows it to be called from anywhere in the application. I build the menu model object within the MenuService as well. I declare the MenuService as a provider in AppModule and initially call it's methods in the ngOnInit() method of the AppMenuComponent.

Re: Dynamic items in menu

Posted: 18 Jul 2018, 10:52
by rahav
to create dynamic menu this is working for me
categoryList is a list of item that is fetch from the DB

categoriesList: Category[];
items: MenuItem[];
item: MenuItem;


for (const i in this.categoriesList) {

this.item = {label: this.categoriesList.categoryName};
this.items.push(this.item);
}