Components: Can't bind to 'matMenuTriggerFor' since it isn't a known property of 'button'. ("">

Created on 25 Sep 2017  路  24Comments  路  Source: angular/components

Bug, feature request, or proposal:

this is for beta11

What is the expected behavior?

should bind submenu to button

What is the current behavior?

does not do that

What are the steps to reproduce?

try to bind [matMenuTriggerFor]="someSubMenu"

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: https://goo.gl/DlHd6U

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Material beta 11

Is there anything else we should know?

cannot reproduce

Most helpful comment

It is not sufficient to add the imports to the application module, alone. To fix this issue, add imports into any component spec beforeEach that is using the material as well. e.g:

mycomponent.spec.ts
`imports: [ // Anything that uses the Materials lib needs to import in order to test

MatMenuModule,

MatIconModule,

MatButtonModule

]`
In this case i am using Menu, Icon, and Buttons

All 24 comments

Can you provide a reproduction of the issue?

Based on the error you are receiving it appears that you are not importing MatMenuModule

It looks like you could be on an older Angular version. Can you update to 4.4.3?

I did it fixed the error!

However, now it does not like

import {MatSnackBar} from '@angular/material'

suggestions?

What error are you getting?

Module '"path/to/node_modules/@angular/material/material"' has no exported member 'MatSnackBar'.

You should be able to import MdSnackBar.

I thought it was called MatSnackBar with the prefix changes

We're still in the process of renaming a lot of things. See https://github.com/angular/material2/pull/7241.

So for the time being, should I be using MdSnackBar?

But my module is MatSnackBarModule?

Yes, it is a little confusing but it will be sorted out by the time we hit stable. Your IDEs autocompletion should be able to give you the proper import names.

Okay, is MdSnackBar now considered a service?

I dont understand why an npm package is provided that renames everything to Mat from Md, however this is not stable. This may ruin alot of peoples code.

It does ruin a lot of code. I also though that the tool would grab what is changeable, but it seems that it converted too much (i have similar issues with Modules like mat-option not liking [value] and styles being completely off). There should be a warning about using this service.

Closing as the issue was resolved by updating to @angular/[email protected]

getting the same issue, please help me.

Facing same issue with newer versions of material and angular. I only face the issue running the test specs. I will upgrade these to see if it still occurs.

Steps:
Used this template HTML reference https://stackblitz.com/angular/rkjvvyxqymb?file=app%2Fmenu-overview-example.ts and generated a component with angular cli. Run the test and boom 馃挜

Node: v8.9.4
NPM: v5.6.0

"@angular/animations": "^5.2.4",
"@angular/cdk": "^5.2.1",
"@angular/common": "^5.2.4",
"@angular/compiler": "^5.2.4",
"@angular/core": "^5.2.4",
"@angular/forms": "^5.2.4",
"@angular/http": "^5.2.4",
"@angular/material": "^5.2.1",
"@angular/platform-browser": "^5.2.4",
"@angular/platform-browser-dynamic": "^5.2.4",
"@angular/router": "^5.2.4",

I am experiencing the same as @Gavintek.
Angular CLI: 6.0.7 Node: 10.1.0 OS: darwin x64 Angular: 6.0.3
@angular-devkit/architect 0.6.7 @angular-devkit/build-angular 0.6.7 @angular-devkit/build-optimizer 0.6.7 @angular-devkit/core 0.6.7 @angular-devkit/schematics 0.6.7 @angular/cdk 6.2.0 @angular/cli 6.0.7 @angular/material 6.2.0 @ngtools/webpack 6.0.7 @schematics/angular 0.6.7 @schematics/update 0.6.7 rxjs 6.2.0 typescript 2.7.2 webpack 4.8.3

Test Spec:

`import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { ToolmenuComponent } from './toolmenu/toolmenu.component';
import { ToolboxComponent } from './toolbox/toolbox.component';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
ToolmenuComponent,
ToolboxComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
.....
});`

Implementation:
<button class="tool-menu" mat-button [matMenuTriggerFor]="imageMenu">Image Tools</button>

Karma Stack:

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

It is not sufficient to add the imports to the application module, alone. To fix this issue, add imports into any component spec beforeEach that is using the material as well. e.g:

mycomponent.spec.ts
`imports: [ // Anything that uses the Materials lib needs to import in order to test

MatMenuModule,

MatIconModule,

MatButtonModule

]`
In this case i am using Menu, Icon, and Buttons

Thanks @DougReynolds - this works, however, it'd maybe be a bit better to update the documentation section for the API to show that more than 1 module is required for this?

At the moment I've had to do the same thing with other components, but it's just trial and error at this point. Everything else has worked perfectly :) <3

Same problem with angular v6.1.6, i have MatMenuModule, MatIconModule, MatButtonModule and MatSnackBarModule

@JarekSour , how did you solve it?

Well:
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';

in the app.module.ts.

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

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MurhafSousli picture MurhafSousli  路  3Comments

dzrust picture dzrust  路  3Comments

savaryt picture savaryt  路  3Comments

crutchcorn picture crutchcorn  路  3Comments

LoganDupont picture LoganDupont  路  3Comments