Ideally, I would need to reload / reload my component template, but if there is a better way to do this, I will gladly implement it.
Desired behavior:
So, I have a component for a menu item. When (in another component) I click IBO (click-to-click), I need to add (I use *ngIf ) a new option in the menu, which will be IBO Details and a child of the list.
Component
IBOsNavigationElement (menu component):
@Component({ selector: '[ibos-navigation-element]', template: ` <a href="#"><i class="fa fa-lg fa-fw fa-group"></i> <span class="menu-item-parent">{{'IBOs' | i18n}}</span> </a> <ul> <li routerLinkActive="active"> <a routerLink="/ibos/IBOsMain">{{'IBOs Main' | i18n}} {{id}}</a> </li> <li *ngIf="navigationList?.length > 0"> <a href="#">{{'IBO Details' | i18n}}</a> <ul> <li routerLinkActive="active" *ngFor="let navigatedIBO of navigationList"> <a href="#/ibos/IboDetails/{{navigatedIBO['id']}}">{{navigatedIBO['name']}}</a> </li> </ul> </li> </ul> ` }) export class IBOsNavigationElement implements OnInit { private navigationList = <any>[]; constructor(private navigationService: NavigationElementsService) { this.navigationService.updateIBOsNavigation$.subscribe((navigationData) => { this.navigationList.push(navigationData); log.d('I received this Navigation Data:', JSON.stringify(this.navigationList)); } ); } ngOnInit() { } }
Initially, the navigationList will be empty [] , because the user has not clicked a single IBO (client), but as soon as the IBO is called, the list will be filled, and therefore I need a new option to display on the menu.
With this code, when I press IBO, the <li> element and its children are created, but: I only see the <li> element.
Question:
A menu option is generated but not executed by layout styles. It must be initialized with all the elements in order to know how to display the menu options.
I need to reload the template of this component in order to display the menu correctly.
Note:
If I use a template without *ngIf , it works well, but from the first moment I would get the IBO Details option, which makes no sense, because no one clicked during initialization.
template: ` <a href="#"><i class="fa fa-lg fa-fw fa-group"></i> <span class="menu-item-parent">{{'IBOs' | i18n}}</span> </a> <ul> <li routerLinkActive="active"> <a routerLink="/ibos/IBOsMain">{{'IBOs Main' | i18n}} {{id}}</a> </li> <li> <a href="#">{{'IBO Details' | i18n}}</a> <ul> <li routerLinkActive="active" *ngFor="let navigatedIBO of navigationList"> <a href="#/ibos/IboDetails/{{navigatedIBO['id']}}">{{navigatedIBO['name']}}</a> </li> </ul> </li> </ul> `
Desired Result:
Before clicking on anything (in init):

After I clicked IBO (client):

Update 1:
To clarify what I had in mind:
Menu option generated but not executed by layout styles
If my menu component is initialized without *ngIf :
<li> <a href="#">{{'IBO Details' | i18n}}</a> <ul> <li routerLinkActive="active" *ngFor="let navigatedIBO of navigationList"> <a href="#/ibos/IboDetails/{{navigatedIBO['id']}}">{{navigatedIBO['name']}}</a> </li> </ul> </li>
Then, the layout styles can generate menu output (see images) in accordance with this structure:
<li> <a> <ul> <li *ngFor> <a> </li> </ul> </li>
And therefore add the + symbol, submenu behavior, etc.
But if it is initialized without all elements (when *ngIf is false <li> , and its children are not displayed, therefore the layout does not take them into account for drawing / creating menus), and these elements are added after rendering, then they will exist in the source code, but we won’t be able to see them on the menu, because:
- No
+ created - Lack of submenu behavior