繁体   English   中英

将Material Design导入Angular 2 + Webpack

[英]Import Material design to Angular 2 + webpack

我是Angular 2的新手,有一个问题,我使用Angular2 + webpack,我正在导入Angular Material组件,但是它不起作用

 ////////////////// // WEBPACK /////////// new DllBundlesPlugin({ bundles: { '@angular/material', } }) // APP MODULE import { MaterialModule } from '@angular/material'; // Should I use @angular/material or @angular2-material import { MaterialModule } from '@angular2-material'; import 'hammerjs'; @NgModule({ imports: [MetarialModule.forRoot()] }) // COMPONENT // import { MdButton } from '@angular/material'; import { MdButton } from '@angular2-material/button'; @Component({ selector: 'test', templateUrl: './test.html', directive: [MdButton] // It says //Generic type 'Type<T>' requires 1 type argument(s) // Argument of type '{ selector: string; template: any; directives: typeof MdButton[]; }' is not assignable to parameter of type 'Component'. //Object literal may only specify known properties, and 'directives' does not exist in type 'Component'. }) 

我使用的是错误版本还是未包含?

@angular2-material已过时且已弃用。

您应该使用@angular/material

我不确定最新版本中是否需要MetarialModule.forRoot()。 我认为无论如何您都可以离开它,但很快就会弃用。

在模块中导入MaterialModule时,不需要一个个地导入每个材料组件。 您将可以直接访问它们。

如果要在导入的MetarialModule.forRoot()模块之外的其他模块中使用材质,请记住要导入( )MaterialModule。


友好的建议[主题外]:

我是Angular 2的新手,我使用Angular2 + webpack时遇到问题

如果您不想自己处理这类事情并专注于Angular,则应该使用angular-cli

如果您想尝试使用最新版本:

npm install -g @angular/cli
ng new your-awesome-project
cd your-awesome-project
ng serve

您现在已设置setup。

要构建: ng build --prod

在Github仓库中查看一下,您可以使用ng generate ...等命令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM