<ul nz-menu nzMode="inline">
<!-- <ng-container *ngFor="let route of routes">
<li *ngIf="route.path && route.data?.name" nz-menu-item [nzSelected]="isRouteSelected(route)" [routerLink]="["/" + route.path]">{{ route.data.name }}</li>
</ng-container> -->
<ng-container *ngFor="let item of menu">
<li *ngIf="!item.son" nz-menu-item [nzSelected]="isMenuSelected(item)" data-id="1" (nzClick)="getMenuItem($event)" [routerLink]="["/" + item.action_url]">{{ item.action_name }}</li>
<li *ngIf="item.son" nz-submenu>
<div title>{{ item.action_name }}</div>
<ul>
<ng-container *ngFor="let sonItem of item.son">
<li *ngIf="sonItem.action_type < 3" [nzSelected]="isMenuSelected(sonItem)" data-id="2" (nzClick)="getMenuItem($event)" nz-menu-item [routerLink]="["/" + sonItem.action_url]">{{ sonItem.action_name }}</li>
</ng-container>
</ul>
</li>
</ng-container>
</ul>
import { Component, isDevMode } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { AppRoute } from "@/app/app.route";
import { ApiService } from "@/services/api.service";
import { UtilService } from "@/services/util.service";
@Component({
templateUrl: "./basic.html",
})
export class BasicLayout {
username = localStorage.getItem("username");
breadcrumb = [];
routes = !isDevMode() ? AppRoute : null;
menu;
isRouteSelected(route) {
const pathRE = new RegExp(`^/${route.path}[;/?-sharp$]`);
return pathRE.test(this.router.url);
}
isMenuSelected(menu) {
const pathRE = new RegExp(`^/${menu.action_url}[;/?-sharp$]`);
return pathRE.test(this.router.url);
}
getMenuItem(e:any):void {
console.log("aa")
console.log(e)
}
setBreadcrumb(snapshot) {
let breadcrumb = [];
let route = snapshot.root;
while (route) {
if (route.url.length) {
breadcrumb.push({
title: route.data.name,
href: "/" + breadcrumb.map(b => b.href).concat(route.routeConfig.path).join("/"),
});
}
route = route.firstChild;
}
this.breadcrumb = breadcrumb;
}
async onClickLogout() {
await this.api.put("login/logout")({
user_id: localStorage.getItem("user.id"),
});
localStorage.clear();
this.util.navigate(["user/login"]);
}
async ngOnInit() {
this.setBreadcrumb(this.route.snapshot);
this.util.resolveStart.subscribe(e => this.setBreadcrumb(e["state"]));
const { data } = await this.api.get("user/menu")();
this.menu = data;
}
constructor(
private api: ApiService,
private route: ActivatedRoute,
private router: Router,
private util: UtilService,
) { }
}
Why is there no response here?