简体   繁体   English

将Material Design导入Angular 2 + Webpack

[英]Import Material design to Angular 2 + webpack

I'm new to Angular 2 and have a problem I use Angular2 + webpack, I'm importing Angular Material components but it doesn't work 我是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'. }) 

Am I using wrong version or haven't include something ? 我使用的是错误版本还是未包含?

@angular2-material is quite old and deprecated. @angular2-material已过时且已弃用。

You should use @angular/material . 您应该使用@angular/material

I'm not sure MetarialModule.forRoot() is needed in the latest release. 我不确定最新版本中是否需要MetarialModule.forRoot()。 I think that anyway you can leave it but it'll be deprecated soon. 我认为无论如何您都可以离开它,但很快就会弃用。

As you've imported MaterialModule in your module, you don't need to import every material component one by one. 在模块中导入MaterialModule时,不需要一个个地导入每个材料组件。 You'll have access to them directly. 您将可以直接访问它们。

If you want to use material in an other module than the one you imported MetarialModule.forRoot(), remember to import ( only ) MaterialModule. 如果要在导入的MetarialModule.forRoot()模块之外的其他模块中使用材质,请记住要导入( )MaterialModule。


Friendly advice [off topic]: 友好的建议[主题外]:

I'm new to Angular 2 and have a problem I use Angular2 + webpack 我是Angular 2的新手,我使用Angular2 + webpack时遇到问题

If you don't want to have to handle that kind of things on your own and focus on Angular, you should rather use angular-cli . 如果您不想自己处理这类事情并专注于Angular,则应该使用angular-cli

If you want to give a try with latest version : 如果您想尝试使用最新版本:

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

You're now setup 👍. 您现在已设置setup。

To build : ng build --prod 要构建: ng build --prod

Take a look in the Github repo to be aware of the commands that you can use ng generate ... etc. 在Github仓库中查看一下,您可以使用ng generate ...等命令。

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

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