博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
angular项目中使用angular-material2
阅读量:5142 次
发布时间:2019-06-13

本文共 4026 字,大约阅读时间需要 13 分钟。

Step 1: Install Angular Material and Angular CDK

npm install --save @angular/material @angular/cdk
npm install --save angular/material2-builds angular/cdk-builds

Step 2: Animations

Some Material components depend on the Angular animations module in order to be able to do more advanced transitions. If you want these animations to work in your app, you have to install the @angular/animations module and include the BrowserAnimationsModule in your app.

npm install --save @angular/animations
import {
BrowserAnimationsModule} from '@angular/platform-browser/animations'; @NgModule({ ... imports: [BrowserAnimationsModule], ... }) export class PizzaPartyAppModule { }

If you don't want to add another dependency to your project, you can use the NoopAnimationsModule.

import {
NoopAnimationsModule} from '@angular/platform-browser/animations'; @NgModule({ ... imports: [NoopAnimationsModule], ... }) export class PizzaPartyAppModule { }

Step 3: Import the component modules

Import the NgModule for each component you want to use:

import {
MdButtonModule, MdCheckboxModule} from '@angular/material'; @NgModule({ ... imports: [MdButtonModule, MdCheckboxModule], ... }) export class PizzaPartyAppModule { }

Alternatively, you can create a separate NgModule that imports all of the Angular Material components that you will use in your application. You can then include this module wherever you'd like to use the components.

import {
MdButtonModule, MdCheckboxModule} from '@angular/material'; @NgModule({ imports: [MdButtonModule, MdCheckboxModule], exports: [MdButtonModule, MdCheckboxModule], }) export class MyOwnCustomMaterialModule { }

Whichever approach you use, be sure to import the Angular Material modules after Angular's BrowserModule, as the import order matters for NgModules.

Step 4: Include a theme

Including a theme is required to apply all of the core and theme styles to your application.

To get started with a prebuilt theme, include one of Angular Material's prebuilt themes globally in your application. If you're using the Angular CLI, you can add this to your styles.css:

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

If you are not using the Angular CLI, you can include a prebuilt theme via a <link> element in your index.html.

For more information on theming and instructions on how to create a custom theme, see the .

Step 5: Gesture Support

Some components (md-slide-togglemd-slidermdTooltip) rely on  for gestures. In order to get the full feature-set of these components, HammerJS must be loaded into the application.

You can add HammerJS to your application via , a CDN (such as the ), or served directly from your app.

To install via npm, use the following command:

npm install --save hammerjs

After installing, import it on your app's entry point (e.g. src/main.ts).

import 'hammerjs';

Step 6 (Optional): Add Material Icons

If you want to use the md-icon component with the official , load the icon font in your index.html.

For more information on using Material Icons, check out the .

Note that md-icon supports any font or svg icons; using Material Icons is one of many options.

Appendix: Configuring SystemJS

If your project is using SystemJS for module loading, you will need to add @angular/material and @angular/cdk to the SystemJS configuration.

The @angular/cdk package is organized of multiple entry-points. Each of these entry-points must be registered individually with SystemJS.

Here is a example configuration where @angular/material@angular/cdk/platform and @angular/cdk/a11y are used:

System.config({  // Existing configuration options  map: {    // ... '@angular/material': 'npm:@angular/material/bundles/material.umd.js', // CDK individual packages '@angular/cdk/platform': 'npm:@angular/cdk/bundles/cdk-platform.umd.js', '@angular/cdk/a11y': 'npm:@angular/cdk/bundles/cdk-a11y.umd.js', // ... } });

Example Angular Material projects

  •  - We build our own documentation with Angular Material!

 

转载于:https://www.cnblogs.com/kaid/p/7531800.html

你可能感兴趣的文章
向前引用变量
查看>>
winsock和winsock2冲突
查看>>
(收藏)学习Java的网站
查看>>
http权威指南读书笔记(三)——http报文
查看>>
md5之守株待兔
查看>>
【求助】:关于printf打印信息错误的问题
查看>>
day 54 linux 常用指令入门
查看>>
lua中类的实现原理和实践
查看>>
阿里云对象存储OSS————跨域资源共享(CORS)(m3u8 无法加载m3u8:跨域访问被拒绝)...
查看>>
uva439 - Knight Moves(BFS求最短路)
查看>>
《这样装修最省钱》—— 读后总结
查看>>
如何在Elasticsearch中安装中文分词器(IK+pinyin)
查看>>
Docker安装(centos7.4)
查看>>
userdata
查看>>
威佐夫游戏 51Nod - 1072(威佐夫博弈入门经典题)
查看>>
Hibernate 简易入门教程
查看>>
sed入门详解教程
查看>>
MD5骨骼动画模型加载
查看>>
kubernetes 命令方式 部署、访问应用
查看>>
11:HTML5 发展史
查看>>