无法绑定到"matMenuTriggerFor",因为它不是"button"的已知属性 [英] Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'

查看:488
本文介绍了无法绑定到"matMenuTriggerFor",因为它不是"button"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试测试角度分量时出现以下错误:

I'm getting following error when I try to test an angular component:

运行笑话测试时出错:

Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'.

这是我的html:

<button mat-button [matMenuTriggerFor]="menu">Menu</button>
<mat-menu #menu="matMenu">
  <button mat-menu-item>Item 1</button>
  <button mat-menu-item>Item 2</button>
</mat-menu>`

我在package.json中使用了"@angular/material": "6.1.0",. 我还已经在TestBed下的beforeAll块中导入了所有必需的材料依赖项. 我还尝试将按钮的属性从matMenuTriggerFor更改为mat-menu-trigger-for.没用.

I'm using "@angular/material": "6.1.0", in my package.json. I've also imported all the required material dependencies in the beforeAll block under TestBed I also tried changing the property of the button from matMenuTriggerFor to mat-menu-trigger-for. It didn't work.

请提出如何解决此测试的建议.

Please suggest how can I fix this test.

推荐答案

在功能模块或该组件所在的模块中导入 MatMenuModule .

Import MatMenuModule in your feature Module OR the Module where this component resides in.

 import { MatMenuModule} from '@angular/material/menu';

imports: [
  MatMenuModule
]

这篇关于无法绑定到"matMenuTriggerFor",因为它不是"button"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆