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

我们两清 提交于 2019-11-30 22:20:10

问题


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

Error while running jest tests:

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

Here is my 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>`

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.


回答1:


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

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

and

imports: [
  MatMenuModule
]



回答2:


I think you need to add the MatMenuModule import to your app.module file.



来源:https://stackoverflow.com/questions/50883873/cant-bind-to-matmenutriggerfor-since-it-isnt-a-known-property-of-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!