Step 1: Install Angular Material and Angular CDK

  1. npm install --save @angular/material @angular/cdk
  1. 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.

  1. npm install --save @angular/animations
  1. import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
  2.  
  3. @NgModule({
  4. ...
  5. imports: [BrowserAnimationsModule],
  6. ...
  7. })
  8. export class PizzaPartyAppModule { }

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

  1. import {NoopAnimationsModule} from '@angular/platform-browser/animations';
  2.  
  3. @NgModule({
  4. ...
  5. imports: [NoopAnimationsModule],
  6. ...
  7. })
  8. export class PizzaPartyAppModule { }

Step 3: Import the component modules

Import the NgModule for each component you want to use:

  1. import {MdButtonModule, MdCheckboxModule} from '@angular/material';
  2.  
  3. @NgModule({
  4. ...
  5. imports: [MdButtonModule, MdCheckboxModule],
  6. ...
  7. })
  8. 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.

  1. import {MdButtonModule, MdCheckboxModule} from '@angular/material';
  2.  
  3. @NgModule({
  4. imports: [MdButtonModule, MdCheckboxModule],
  5. exports: [MdButtonModule, MdCheckboxModule],
  6. })
  7. 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:

  1. @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 theming guide.

Step 5: Gesture Support

Some components (md-slide-togglemd-slidermdTooltip) rely on HammerJS 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 npm, a CDN (such as the Google CDN), or served directly from your app.

To install via npm, use the following command:

  1. npm install --save hammerjs

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

  1. import 'hammerjs';

Step 6 (Optional): Add Material Icons

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

  1. <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

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

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:

  1. System.config({
  2. // Existing configuration options
  3. map: {
  4. // ...
  5. '@angular/material': 'npm:@angular/material/bundles/material.umd.js',
  6.  
  7. // CDK individual packages
  8. '@angular/cdk/platform': 'npm:@angular/cdk/bundles/cdk-platform.umd.js',
  9. '@angular/cdk/a11y': 'npm:@angular/cdk/bundles/cdk-a11y.umd.js',
  10. // ...
  11. }
  12. });

Example Angular Material projects

angular项目中使用angular-material2的更多相关文章

  1. gulp 在 angular 项目中的使用

    gulp 在 angular 项目中的使用 keyword:gulp,angularjs,ng,ngAnnotate,jshint,gulpfile 最后附完整简洁的ng项目gulpfile.js 准 ...

  2. angular项目中各个文件的作用

    原文地址 https://www.jianshu.com/p/176ea79a7101 大纲 1.对angular项目中的一些文件的概述 2.对其中一些文件的详细描述 2.1.package.json ...

  3. Angular 项目中如何使用 ECharts

    在有些使用 ECharts 库的 Angular 项目中,通常除了安装 npm 包之外,还会在 angular.json 中配置 “build.options.scripts”,将 “node_mod ...

  4. angular项目中遇到的问题

    一.angular项目中如何实现路由缓存 需要实现的效果,对请求的数据进行缓存,比如进入文章详情页之后点击返回,不会再调用后台数据接口:而是加载缓存中的数据,如何数据变动的情况下,可使用下拉刷新刷新页 ...

  5. 项目中遇到angular时间插件datetinepicker汉化问题

    问题描述: 测试需要中文的时间插件: 参考资料: angularjs封装bootstrap官网的时间插件datetimepicker https://www.cnblogs.com/cynthia-w ...

  6. angular项目中使用Primeng

    1.第一步把依赖添加到项目中 npm install primeng --save npm install @angular/animations --save npm install font-aw ...

  7. Angular项目中引入jQuery

    npm install --save jquery npm install @types/jquery --save 在对应的组件中引入 import * as $ from "jquery ...

  8. 在angular项目中使用bootstrap的tooltip插件时,报错Property 'tooltip' does no t exist on type 'JQuery<HTMLElement>的解决方法和过程

    在angular4的项目中需要使用bootstrap的tooltip插件. 1. 使用命令安装jQuery和bootstrap npm install bootstrap jquery --save ...

  9. angular项目中使用jquery的问题

    1.使用npm命令往项目中添加jQuery. npm install jquery --save 2.在你想要用jQuery的组件中添加. import * as $ from "jquer ...

随机推荐

  1. 求n!中因子k的个数

    思路: 求n的阶乘某个因子k的个数,如果n比较小,可以直接算出来,但是如果n很大,此时n!超出了数据的表示范围,这种直接求的方法肯定行不通.其实n!可以表示成统一的方式. n!=(km)*(m!)*a ...

  2. svn和git的区别及适用场景

    svn和git的区别及适用场景 来源 https://blog.csdn.net/wz947324/article/details/80104621 svn的优势: 优异的跨平台支持,对windows ...

  3. poj2549 Sumsets

    Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11886   Accepted: 3273 Descript ...

  4. [CodeForces]String Reconstruction

    http://codeforces.com/contest/828/problem/C 并查集的神奇应用. #include<bits/stdc++.h> using namespace ...

  5. php输出控制函数存在的意义

    因为http协议的限制(前几行必须是协议信息,然后一个空行,然后才是用户需要的内容), 需要保证header信息在其他内容之前发送,否则浏览器无法解析服务器返回的内容.

  6. Mac 开发装机必备

    ==============设置=========================== Mac 启动台图标大小调整 1.终端运行命令:10代表一行显示10个图标,几个可以自定义 defaults wr ...

  7. /etc/rc.d/里文件的作用

    rc.sysinit指的是系统启动不管进哪个运行级别必须做的初始化工作, rcn.d目录指的是系统进对应n的运行级别时候系统必须做的工作,目录下S打头的服务指进此运行级别时候启动的服务,而K打头的指离 ...

  8. java项目转换依赖等问题

    最近接手了一个原始的java项目,其实很久没有做了,自从两年前用maven,建立web项目,java project基本上就没有弄个,突然的接手,发现自己好多不足,可能对于一开始就做这样的容易,但是对 ...

  9. bzoj 3678 wangxz与OJ

    3678: wangxz与OJ Time Limit: 10 Sec  Memory Limit: 128 MBhttp://www.lydsy.com/JudgeOnline/problem.php ...

  10. ZOJ 3780 E - Paint the Grid Again 拓扑排序

    https://vjudge.net/problem/49919/origin 题意:给你n*n只出现O和X的字符阵.有两种操作,一种操作Ri将i行全变成X,一种操作Ci将i列全变成O,每个不同的操作 ...