Here is the code snippet that I am working with:
<a *ngIf="!menuItem.children" (mouseenter)="onHoverItem($event, item)" [routerLink]="[menuItem.url, menuItem.code]" [target]="menuItem.target" class="al-sidebar-list-link">
<i *ngIf="menuItem.icon" class="{{ menuItem.icon }}"></i><span>{{ menuItem.title }}</span>
</a>
However, some of the links are showing this URL:
http://localhost:3000/URL/undefined
This happens because not all menuItems
have a value for the code
property.
To address this issue in Angular, I want to implement the following logic:
If the menuItem.code
is defined:
<a *ngIf="!menuItem.children" (mouseenter)="onHoverItem($event, item)" [routerLink]="[menuItem.url, menuItem.code]" [target]="menuItem.target" class="al-sidebar-list-link">
<i *ngIf="menuItem.icon" class="{{ menuItem.icon }}"></i><span>{{ menuItem.title }}</span>
</a>
Otherwise:
<a *ngIf="!menuItem.children" (mouseenter)="onHoverItem($event, item)" [routerLink]="[menuItem.url]" [target]="menuItem.target" class="al-sidebar-list-link">
<i *ngIf="menuItem.icon" class="{{ menuItem.icon }}"></i><span>{{ menuItem.title }}</span>
</a>