首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >材料模块中断角度2快速入门

材料模块中断角度2快速入门
EN

Stack Overflow用户
提问于 2017-06-15 09:33:11
回答 2查看 626关注 0票数 0

我已经在我的Angular 2快速入门应用程序中安装了材料设计模块,但是当我在app.module.ts中导入该模块时,应用程序似乎崩溃了。

这是在app.module.ts中的设置

代码语言:javascript
复制
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 { }

我得到以下错误:

代码语言:javascript
复制
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'.

以前有没有人遇到过这个问题?

EN

回答 2

Stack Overflow用户

发布于 2017-06-15 09:48:55

Angular Material团队实际上希望将用户从只将MaterialModule导入到他们的应用程序中转移到您需要的组件的模块中。(这与捆绑树抖动保持您不使用的组件的问题有关),您可以在getting started guide here中看到这一点。

请注意,这有点麻烦,所以我通常自己导入整个模块。无论如何,我看到您遗漏的一件事是在步骤2中提到的BrowserAnimationsModule的包含。

尝试将您的模块修改为...

代码语言:javascript
复制
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 { }
票数 1
EN

Stack Overflow用户

发布于 2017-06-15 10:10:53

很难找到最新版本的正确设置。在最新的angular material版本中,不需要导入MaterialModule。

您可以从here下载或派生angular-quickstart样板,该项目具有最新的稳定支持angular material 2.0.0-beta.6和angular 4.0.0,以避免您的麻烦。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44557174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档