我已经在我的Angular 2快速入门应用程序中安装了材料设计模块,但是当我在app.module.ts中导入该模块时,应用程序似乎崩溃了。
这是在app.module.ts中的设置
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MaterialModule } from '@angular/material';
import { MessagesComponent} from './messages-component';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule, MaterialModule ],
declarations: [ AppComponent, MessagesComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }我得到以下错误:
node_modules/@angular/material/typings/button/button.d.ts(40,22): error TS2420: Class 'MdButton' incorrectly implements interface 'CanDisabl
e'.
Property 'disabled' is missing in type 'MdButton'.
node_modules/@angular/material/typings/button/button.d.ts(40,39): error TS2507: Type '(new (...args: any[]) => CanDisable) & typeof MdButton
Base' is not a constructor function type.
node_modules/@angular/material/typings/checkbox/checkbox.d.ts(43,22): error TS2420: Class 'MdCheckbox' incorrectly implements interface 'Can
Disable'.
Property 'disabled' is missing in type 'MdCheckbox'.
node_modules/@angular/material/typings/checkbox/checkbox.d.ts(43,41): error TS2507: Type '(new (...args: any[]) => CanDisable) & typeof MdCh
eckboxBase' is not a constructor function type.
node_modules/@angular/material/typings/dialog/dialog-container.d.ts(2,32): error TS2307: Cannot find module '@angular/animations'.
node_modules/@angular/material/typings/menu/menu-animations.d.ts(1,42): error TS2307: Cannot find module '@angular/animations'.
node_modules/@angular/material/typings/radio/radio.d.ts(24,22): error TS2420: Class 'MdRadioGroup' incorrectly implements interface 'CanDisa
ble'.
Property 'disabled' is missing in type 'MdRadioGroup'.
node_modules/@angular/material/typings/radio/radio.d.ts(24,43): error TS2507: Type '(new (...args: any[]) => CanDisable) & typeof MdRadioGro
upBase' is not a constructor function type.
node_modules/@angular/material/typings/select/select-animations.d.ts(1,42): error TS2307: Cannot find module '@angular/animations'.
node_modules/@angular/material/typings/slide-toggle/slide-toggle.d.ts(14,22): error TS2420: Class 'MdSlideToggle' incorrectly implements int
erface 'CanDisable'.
Property 'disabled' is missing in type 'MdSlideToggle'.
node_modules/@angular/material/typings/slide-toggle/slide-toggle.d.ts(14,44): error TS2507: Type '(new (...args: any[]) => CanDisable) & typ
eof MdSlideToggleBase' is not a constructor function type.
node_modules/@angular/material/typings/slider/slider.d.ts(26,22): error TS2420: Class 'MdSlider' incorrectly implements interface 'CanDisabl
e'.
Property 'disabled' is missing in type 'MdSlider'.
node_modules/@angular/material/typings/slider/slider.d.ts(26,39): error TS2507: Type '(new (...args: any[]) => CanDisable) & typeof MdSlider
Base' is not a constructor function type.
node_modules/@angular/material/typings/snack-bar/snack-bar-container.d.ts(2,32): error TS2307: Cannot find module '@angular/animations'.
node_modules/@angular/material/typings/tabs/tab-body.d.ts(2,32): error TS2307: Cannot find module '@angular/animations'.
node_modules/@angular/material/typings/tooltip/tooltip.d.ts(2,32): error TS2307: Cannot find module '@angular/animations'.以前有没有人遇到过这个问题?
发布于 2017-06-15 09:48:55
Angular Material团队实际上希望将用户从只将MaterialModule导入到他们的应用程序中转移到您需要的组件的模块中。(这与捆绑树抖动保持您不使用的组件的问题有关),您可以在getting started guide here中看到这一点。
请注意,这有点麻烦,所以我通常自己导入整个模块。无论如何,我看到您遗漏的一件事是在步骤2中提到的BrowserAnimationsModule的包含。
尝试将您的模块修改为...
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MaterialModule } from '@angular/material';
import { MessagesComponent} from './messages-component';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
MaterialModule
],
declarations: [
AppComponent,
MessagesComponent
],
bootstrap:[ AppComponent ]
})
export class AppModule { }发布于 2017-06-15 10:10:53
很难找到最新版本的正确设置。在最新的angular material版本中,不需要导入MaterialModule。
您可以从here下载或派生angular-quickstart样板,该项目具有最新的稳定支持angular material 2.0.0-beta.6和angular 4.0.0,以避免您的麻烦。
https://stackoverflow.com/questions/44557174
复制相似问题