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

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

问题描述

当我尝试测试角度组件时出现以下错误:

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

运行 Jest 测试时出错:

Error while running jest tests:

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天全站免登陆