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

前端 未结 6 1237
执笔经年
执笔经年 2021-01-03 17:15

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 i         


        
相关标签:
6条回答
  • 2021-01-03 17:53

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

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

    and

    imports: [
      MatMenuModule
    ]
    
    0 讨论(0)
  • 2021-01-03 17:59

    Check the spelling I had one g in word trigger that cost me this error

    [matMenuTrigerData] => [matMenuTriggerData] 
    
    0 讨论(0)
  • 2021-01-03 18:11

    I got this (and several other errors) because I failed to add the component to the declarations array in the lib.module.ts file.

    0 讨论(0)
  • 2021-01-03 18:13

    I was getting this error while running jest test. I had to add MatMenuModule in the import array of TestBed.configureTestingModule to resolve this error.

    0 讨论(0)
  • 2021-01-03 18:15

    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"
    
    0 讨论(0)
  • 2021-01-03 18:19

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

    0 讨论(0)
提交回复
热议问题