Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'
Solution 1
Import MatMenuModule
in your feature Module OR the Module where this component resides in.
import { MatMenuModule} from '@angular/material/menu';
and
imports: [
MatMenuModule
]
Solution 2
I think you need to add the MatMenuModule import to your app.module file.
Solution 3
Random but in case someone was searching like me: I was importing a custom angular material library and building the consuming library before building the material library. when I built the material library first then the consuming library was about to see the MatMenuModule and errors went away.
I changed
"library:build": "npm run ng7-common:build" && npm run ng8-material:build
to:
"library:build": " npm run ng8-material:build && npm run ng7-common:build"
RV.
Full stack developer. I've mostly used Java with many frameworks as backend technology. On the frontend I've got experience in using JS, jQuery, React, Angularjs, Angular. On the database front I've used traditional RDBMS, Apache Ignite & Cassandra. AWS Certified Solution Architect.
Updated on July 09, 2022Comments
-
RV. almost 2 years
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 thebeforeAll
block underTestBed
I also tried changing the property of the button frommatMenuTriggerFor
tomat-menu-trigger-for
. It didn't work.Please suggest how can I fix this test.