有什麼不對的代碼: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>
您是否包含MdMenuModule? – pzaenger
@pzaenger:是的,我確實 –
鋤頭是你進口材料模塊嗎? ehat是你的角度版本? – Faisal