src/modules/app-menu/components/app-menu.component.ts
Component to display app-menu based on the options passed as parameters.
OnInit
changeDetection | ChangeDetectionStrategy.OnPush |
encapsulation | ViewEncapsulation.None |
host | { |
selector | stark-app-menu |
templateUrl | ./app-menu.component.html |
Properties |
|
Methods |
|
Inputs |
Accessors |
Public
constructor(logger: StarkLoggingService, routingService: StarkRoutingService, renderer: Renderer2, elementRef: ElementRef)
|
||||||||||||||||||||
Class constructor
Parameters :
|
menuConfig | |
Type : StarkMenuConfig
|
|
Configuration of the menu |
color | |
Type : string
|
|
Inherited from
AbstractStarkUiComponent
|
|
Defined in
AbstractStarkUiComponent:16
|
|
Color theme |
Public ngOnInit |
ngOnInit()
|
Inherited from
AbstractStarkUiComponent
|
Defined in
AbstractStarkUiComponent:71
|
Component lifecycle hook
Returns :
void
|
Public hasSections |
Default value : false
|
Either the component have section or not |
Public logger |
Type : StarkLoggingService
|
Decorators :
@Inject(STARK_LOGGING_SERVICE)
|
- The `StarkLoggingService` instance of the application.
|
Public routingService |
Type : StarkRoutingService
|
Decorators :
@Inject(STARK_ROUTING_SERVICE)
|
- The `StarkRoutingService` instance of the application.
|
menuConfig | ||||||
getmenuConfig()
|
||||||
setmenuConfig(menuConfig: StarkMenuConfig)
|
||||||
Configuration of the menu
Parameters :
Returns :
void
|
import { ChangeDetectionStrategy, Component, ElementRef, Inject, Input, OnInit, Renderer2, ViewEncapsulation } from "@angular/core";
import { STARK_LOGGING_SERVICE, STARK_ROUTING_SERVICE, StarkLoggingService, StarkRoutingService } from "@nationalbankbelgium/stark-core";
import { AbstractStarkUiComponent } from "@nationalbankbelgium/stark-ui/src/internal-common";
import { StarkMenuSection } from "./app-menu-section.intf";
import { StarkMenuConfig } from "./app-menu-config.intf";
import { StarkMenuGroup } from "./app-menu-group.intf";
/**
* @ignore
*/
const componentName = "stark-app-menu";
/**
* Component to display app-menu based on the options passed as parameters.
*/
@Component({
selector: "stark-app-menu",
templateUrl: "./app-menu.component.html",
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
// We need to use host instead of @HostBinding: https://github.com/NationalBankBelgium/stark/issues/664
host: {
class: componentName
}
})
export class StarkAppMenuComponent extends AbstractStarkUiComponent implements OnInit {
/**
* @internal
* @ignore
*/
private _menuConfig: StarkMenuConfig = {};
/**
* Configuration of the menu
*/
@Input()
public set menuConfig(menuConfig: StarkMenuConfig) {
this._menuConfig = menuConfig;
// eslint-disable-next-line no-prototype-builtins
this.hasSections = this._menuConfig.hasOwnProperty("menuSections");
}
public get menuConfig(): StarkMenuConfig {
return this._menuConfig;
}
/**
* Either the component have section or not
*/
public hasSections = false;
/**
* Class constructor
* @param logger - The `StarkLoggingService` instance of the application.
* @param routingService - The `StarkRoutingService` instance of the application.
* @param renderer - Angular `Renderer2` wrapper for DOM manipulations.
* @param elementRef - Reference to the DOM element where this component is attached to.
*/
public constructor(
@Inject(STARK_LOGGING_SERVICE) public logger: StarkLoggingService,
@Inject(STARK_ROUTING_SERVICE) public routingService: StarkRoutingService,
renderer: Renderer2,
elementRef: ElementRef
) {
super(renderer, elementRef);
}
/**
* Component lifecycle hook
*/
public override ngOnInit(): void {
super.ngOnInit();
this.logger.debug(componentName + ": component initialized");
}
/**
* @ignore
*/
public trackSection(index: number, _section: StarkMenuSection): number {
return index;
}
/**
* @ignore
*/
public trackMenuGroup(index: number, _menuGroup: StarkMenuGroup): number {
return index;
}
}
<nav>
<ng-container *ngIf="hasSections">
<section *ngFor="let section of menuConfig.menuSections; trackBy: trackSection">
<h2 class="stark-section-title" translate>{{ section.label }}</h2>
<mat-nav-list *ngFor="let menuGroup of section.menuGroups">
<stark-app-menu-item [level]="1" [menuGroup]="menuGroup"></stark-app-menu-item>
</mat-nav-list>
</section>
</ng-container>
<ng-container *ngIf="!hasSections">
<mat-nav-list *ngFor="let menuGroup of menuConfig.menuGroups; trackBy: trackMenuGroup">
<stark-app-menu-item [level]="1" [menuGroup]="menuGroup"></stark-app-menu-item>
</mat-nav-list>
</ng-container>
</nav>