我的 Angular 项目有问题。我无法仅获取菜单的一个组件并将其放在导航上以显示单击了哪个菜单。
这是我的header.component.html
<mat-nav-list>
<mat-list-item>
<a style="color: white;" *ngFor="let menuitem of menuItems.getMenuitem()">{{ menuitem.name }}</a>
</mat-list-item>
</mat-nav-list>
这是我的header.component.ts
import { MediaMatcher } from '@angular/cdk/layout';
import { Router } from '@angular/router';
import {
ChangeDetectorRef,
Component,
NgZone,
OnDestroy,
ViewChild,
HostListener,
Directive,
AfterViewInit
} from '@angular/core';
import { MenuItems } from '../../../shared/menu-items/menu-items';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: []
})
export class AppHeaderComponent implements OnDestroy, AfterViewInit {
mobileQuery: MediaQueryList;
private _mobileQueryListener: () => void;
constructor(
changeDetectorRef: ChangeDetectorRef,
media: MediaMatcher,
public menuItems: MenuItems
) {
this.mobileQuery = media.matchMedia('(min-width: 768px)');
this._mobileQueryListener = () => changeDetectorRef.detectChanges();
this.mobileQuery.addListener(this._mobileQueryListener);
}
ngOnDestroy(): void {
this.mobileQuery.removeListener(this._mobileQueryListener);
}
ngAfterViewInit() {}
}
阿波罗的战车
慕尼黑8549860
跃然一笑
缥缈止盈
相关分类