【发布时间】:2025-11-24 10:40:01
【问题描述】:
Angular 材质菜单模块有点问题。
我的 app.module.ts 中有这段代码:
import { SharedModule } from './shared/shared.module';
@NgModule({
declarations: [
// ...
],
imports: [
SharedModule,
],
})
export class AppModule { }
在我的shared.module.ts中:
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MatMenuModule } from '@angular/material/menu';
import { ListDropdownComponent } from './list-dropdown/list-dropdown.component';
@NgModule({
declarations: [
ListDropdownComponent,
],
imports: [
MatMenuModule,
],
exports: [
ListDropdownComponent,
],
})
export class SharedModule { }
在我的 list-dropdown.component.ts 中:
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
@Component({
selector: 'app-list-dropdown',
templateUrl: './list-dropdown.component.html',
styleUrls: ['./list-dropdown.component.scss']
})
export class ListDropdownComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
在list-dropdown.component.html中:
<button mat-icon-button [matMenuTriggerFor]="menu">
My dropdown menu
</button>
<mat-menu #menu="matMenu">
<!-- ... -->
</mat-menu>
然后我有这个错误信息:
Error: Export of name 'matMenu' not found!
我看不出问题出在哪里?
【问题讨论】:
-
你可能需要重启
ng serve -
需要 BrowserAnimationsModule 吗?
-
感谢@PoulKruijt,重启有帮助。
-
感谢兄弟的帮助
标签: angular typescript angular-material angular9