Angular 15.2.2中mat-menu正常识别但mat-menu-item无法识别求助
在Angular Material 15及以后版本中,<mat-menu-item>独立组件已被移除,需通过在<button>或<a>元素上添加mat-menu-item指令来定义菜单项。
修正后的代码
<button mat-icon-button [matMenuTriggerFor]="menu"> <mat-icon>notifications</mat-icon> </button> <mat-menu #menu="matMenu"> <button mat-menu-item>Notification 1</button> </mat-menu>
模块导入验证
你当前导入的MatMenuModule和MatIconModule是正确的,无需额外新增模块——mat-menu-item指令已包含在MatMenuModule中。
扩展用法示例
如果需要为菜单项添加图标或多行内容,可结合MatIconModule实现:
<button mat-menu-item> <mat-icon>mark_unread</mat-icon> <span>Notification 1</span> </button>
内容的提问来源于stack exchange,提问作者user3586286
相关产品推荐
相关产品推荐

