angular项目中使用angular-material2

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 "[email protected]/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:

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 Material Design Icons, load the icon font in your index.html.

<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:

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

时间: 2024-07-28 15:11:26

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

angular项目中各个文件的作用

原文地址 https://www.jianshu.com/p/176ea79a7101 大纲 1.对angular项目中的一些文件的概述 2.对其中一些文件的详细描述 2.1.package.json 2.2.tsconfig.json 2.3.Polyfills 对angular项目中的一些文件的概述 angular-cli.json Angular CLI 的配置文件. 在这个文件中,你可以设置一系列默认值,还可以配置项目编译时要包含的那些文件. karma.conf.js karma 测试

angular项目中使用Primeng

1.第一步把依赖添加到项目中 npm install primeng --save npm install @angular/animations --save npm install [email protected] --save 2.在.angular-cli.json中添加 "styles": [ "styles.css", "../node_modules/primeng/resources/primeng.min.css", &quo

angular项目中使用jQWidgets

Angular CLI with jQWidgets In this tutorial, we will show you how to use https://cli.angular.io/ along with the Angular Components by jQWidgets.Please, follow the step by step instructions below: npm install -g angular-cli ng new myProject cd myProje

angular项目中使用jquery的问题

1.使用npm命令往项目中添加jQuery. npm install jquery --save 2.在你想要用jQuery的组件中添加. import * as $ from "jquery"; 3.就可以正常使用了.

angular项目中常用的npm命令

1:创建项目:ng new name 2:创建模块:ng g component home或者ng g module about.后者多了一个module.ts文件.这里面的home和about都是模块的名字 3:angular material2:npm install --save@angular2-material/core@angular2-material/button@angular2-material/card@angular2-material/radio@angular2-ma

VS2013中实现angular代码智能提示

第一步:在项目同添加angular js文件的引用: 这里使用NuGet包管理器来给项目添加angular js install-pacage angularjs 第二步:添加智能提示js文件 我们下载 angular.intellisense.js 文件,有两个选择: 第一种选择是我们只想在当前这一个项目中使用angular的智能提示功能,那么将下载的angular.intellisense.js放到和angular 的js文件相同的/Scripts目录下. 第二种选择是,我们想在所有的VS项

在Angular项目下使用Umeditor

Umeditor是百度旗下的开源富文本编辑器项目,目前用于百度贴吧,是ueditor的迷你版本. 公司的Angular后台管理项目需要上传一些新闻,用Umeditor十分适合.但是目前官方只提供Jsp,Asp,Php和.net版本,也就是说只支持一般页面应用.而每次初始化编辑器时,都需要加载一次 umeditor.min.js文件: <script type="text/javascript" charset="utf-8" src="./js/li

webstrom bower搭建angular项目

在webstorm中,新建一个angular项目,默认配置的是node的环境[会有一个package.json和bower.json ] 此时在浏览器运行index.html  会报一堆的错 检查了下是因为没有安装bower和angular 安装顺序是: 1.全局安装bower npm install bower -g[此处具体安装和配置省略,需要配置环境变量和设置node的全局安装路径] 2.此时 在任何文件目录下,都可以直接使用bower命令 3.在项目位置处 bower install a

angular 项目回顾

从学习angular,到实际项目开发不到一周,完全是边写边学呀,都是为了项目,已使用angular 开发了两个项目了,有些技术当时只是会用,都没好好回顾一下,现在有时间回顾一下,项目中用到的一些指令,服务,路由,filter 等, 一点点记录一来 // 初始化 angular.bootstrap(dom,['appName']); //html 转化 // 需传参 $sce $scope.escape = function(html) { return $sce.trustAsHtml(html