2017-09-30 78 views
1

有什麼不對的代碼:mdMenu不角材料版本工作:2.0.0-beta.11

<button md-button [mdMenuTriggerFor]="menu">Menu</button> 
<md-menu #menu="mdMenu"> 
    <button md-menu-item>Item 1</button> 
    <button md-menu-item>Item 2</button> 
</md-menu> 

我得到錯誤:

Template parse errors: There is no directive with "exportAs" set to "mdMenu" ("

Menu ]#menu="mdMenu"> Item 1
Item 2 "): ng:///UserModule/[email protected]:9

編輯:1

我也試試這個:

<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> 

我得到這個錯誤:

Template parse errors: There is no directive with "exportAs" set to "matMenu" ("

Menu ]#menu="matMenu"> Item 1
Item 2 "): ng:///UserModule/[email protected]:10

編輯:2

我進口:

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

編輯:3

user.module

import { NgModule } from '@angular/core'; 

import { SharedModule } from '../../shared/shared.module'; 
import { UserRoutingModule } from './user-routing.module'; 
import { UserService } from './user.service'; 

// material 
import { 
    MatCardModule, 
    MatMenuModule, 
    MatInputModule, 
    MatButtonModule, 
    MatCheckboxModule 
} from '@angular/material'; 

import { UserComponent } from './user.component'; 
import { UserProfileComponent } from './user-profile/user-profile.component'; 
import { 
    UserRegistrationComponent 
} from './user-registration/user-registration.component'; 
import { 
    UserRestorePasswordComponent 
} from './user-restore-password/user-restore-password.component'; 

@NgModule({ 
    imports: [ 
    SharedModule, 
    UserRoutingModule, 
    MatCardModule, 
    MatMenuModule, 
    MatInputModule, 
    MatButtonModule, 
    MatCheckboxModule 
    ], 
    declarations: [ 
    UserComponent, 
    UserProfileComponent, 
    UserRegistrationComponent, 
    UserRestorePasswordComponent 
    ], 
    providers: [ 
    UserService 
    ] 
}) 
export class UserModule { } 

這是我user.registration.component.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> 
+0

您是否包含MdMenuModule? – pzaenger

+0

@pzaenger:是的,我確實 –

+0

鋤頭是你進口材料模塊嗎? ehat是你的角度版本? – Faisal

回答

1

問題是與你的角度版本。更新您的角度版本至4.4.3或更高。材料2.0.0-beta.11取決於4.4.3或更高。從CHANGELOG文檔:

Breaking changes Angular Material now requires Angular 4.4.3 or greater

鏈接working demo

+0

非常感謝... –