You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 15.2.2中mat-menu正常识别但mat-menu-item无法识别求助

问题解决: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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 00:29:53