angular ng-zorro menu 点击事件没反应(nzClick)
<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}[;/?#$]`);
return pathRE.test(this.router.url);
}
isMenuSelected(menu) {
const pathRE = new RegExp(`^/${menu.action_url}[;/?#$]`);
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,
) { }
}
为什么这里点击没反应 应该怎么写呢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论