Hi,
How do you think you could implement sub-menus.
I can make them work when the navbar is full screen but when its reduced to a mobile screen they don't work.
I achievd this by using a slightly different version of
navbar.metadata.ts
export enum MenuType {
BRAND,
LEFT,
RIGHT
}
export interface RouteInfo {
path: string;
title: string;
isDropdown: boolean;
menuType: MenuType;
links: any;
}
So my Route is
import { MenuType, RouteInfo } from './navbar.metadata';
export const ROUTES: RouteInfo[] = [
{ path: 'home', title: 'eClaim', menuType: MenuType.BRAND, isDropdown: false, links: null },
{ path: 'maintenance', title: 'Maintain', menuType: MenuType.LEFT, isDropdown: true,
links: [
{ path: 'maintenance/employee', title: 'Employees', menuType: MenuType.LEFT, isDropdown: false, links: null },
{ path: 'counter2', title: 'CounterS2', menuType: MenuType.LEFT, isDropdown: false, links: null },
{ path: 'counter3', title: 'CounterS3', menuType: MenuType.LEFT, isDropdown: false, links: null }
]
},
{
path: 'counter', title: 'CounterT', menuType: MenuType.LEFT, isDropdown: true,
links: [
{ path: 'counter1', title: 'CounterS1', menuType: MenuType.LEFT, isDropdown: false, links: null },
{ path: 'counter2', title: 'CounterS2', menuType: MenuType.LEFT, isDropdown: false, links: null },
{ path: 'counter3', title: 'CounterS3', menuType: MenuType.LEFT, isDropdown: false, links: null }
]
},
{ path: 'about', title: 'About Us', menuType: MenuType.LEFT, isDropdown: false, links: null },
{ path: 'fetch-data', title: 'Weather Data', menuType: MenuType.RIGHT, isDropdown: false, links: null }
];
And within the navbar.component.html the section producing the menu's is
<li (click)="isCollapsed = true" *ngFor="let menuItem of menuItems"
class="nav-item" routerLinkActive="active"
[ngClass]="getMenuItemClasses(menuItem)">
<a class="nav-item nav-link" [routerLink]="[menuItem.path]" routerLinkActive="active" *ngIf="!menuItem.isDropdown">{{menuItem.title}}
<div ngbDropdown class="d-inline-block" *ngIf="menuItem.isDropdown" >
<a (click)="isCollapsed = true" class="nav-link dropdown-toggle" *ngIf="menuItem.isDropdown" ngbDropdownToggle>{{menuItem.title}}
<ul class="dropdown-menu" role="menu" *ngIf="menuItem.isDropdown">
<li (click)="isCollapsed = true" *ngFor="let subItem of menuItem.links"
class="nav-item" routerLinkActive="active"
[ngClass]="getMenuItemClasses(subItem)">
<a class="nav-item nav-link" [routerLink]="[subItem.path]" routerLinkActive="active" *ngIf="!subItem.isDropdown">{{subItem.title}}
All good except when it goes to a small screen. Then the sub menu's do not work. I think they are appearing off the screen to the right
Steve