2017-03-23 22:46:47 +01:00
For help getting started with a new Angular app, check out the
[Angular CLI ](https://cli.angular.io/ ).
2016-05-25 10:10:26 -07:00
2017-03-10 10:41:00 -08:00
For existing apps, follow these steps to begin using Angular Material.
2016-09-13 14:44:43 -07:00
2017-07-05 16:29:35 -07:00
## Step 1: Install Angular Material and Angular CDK
2016-05-25 10:10:26 -07:00
``` bash
2017-07-05 16:29:35 -07:00
npm install --save @angular/material @angular/cdk
2016-05-25 10:10:26 -07:00
```
2017-07-07 14:16:15 -03:00
A snapshot build with the latest changes from master is also available. Note that this snapshot build should not be considered stable and may break between releases.
``` bash
npm install --save angular/material2-builds angular/cdk-builds
```
2017-03-23 22:46:47 +01:00
## 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.
``` bash
npm install --save @angular/animations
```
2016-05-25 10:10:26 -07:00
``` ts
2017-03-23 22:46:47 +01:00
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` .
``` ts
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@NgModule ( {
. . .
imports : [ NoopAnimationsModule ] ,
. . .
} )
export class PizzaPartyAppModule { }
```
2017-04-08 18:10:02 -06:00
## Step 3: Import the component modules
2017-03-23 22:46:47 +01:00
2017-04-08 18:10:02 -06:00
Import the NgModule for each component you want to use:
2017-03-23 22:46:47 +01:00
``` ts
2017-04-08 18:10:02 -06:00
import { MdButtonModule , MdCheckboxModule } from '@angular/material' ;
2017-03-23 22:46:47 +01:00
2016-08-09 11:16:08 -07:00
@NgModule ( {
2017-03-10 10:41:00 -08:00
. . .
2017-04-08 18:10:02 -06:00
imports : [ MdButtonModule , MdCheckboxModule ] ,
2016-08-09 11:16:08 -07:00
. . .
} )
2016-09-27 16:58:55 +01:00
export class PizzaPartyAppModule { }
2016-05-25 10:10:26 -07:00
```
2017-04-08 18:10:02 -06:00
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.
``` ts
import { MdButtonModule , MdCheckboxModule } from '@angular/material' ;
@NgModule ( {
imports : [ MdButtonModule , MdCheckboxModule ] ,
exports : [ MdButtonModule , MdCheckboxModule ] ,
} )
export class MyOwnCustomMaterialModule { }
```
2017-04-26 16:41:40 -07:00
Whichever approach you use, be sure to import the Angular Material modules _ after _ Angular's
`BrowserModule` , as the import order matters for NgModules.
2017-04-08 18:10:02 -06:00
## Step 4: Include a theme
2017-03-10 10:41:00 -08:00
2017-03-23 22:46:47 +01:00
Including a theme is **required ** to apply all of the core and theme styles to your application.
2016-07-04 17:07:48 -07:00
2017-07-05 16:29:35 -07:00
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` :
``` css
@ import "~@angular/material/prebuilt-themes/indigo-pink.css" ;
2017-03-10 10:41:00 -08:00
```
2017-07-05 16:29:35 -07:00
If you are not using the Angular CLI, you can include a prebuilt theme via a `<link>` element in
your `index.html` .
2017-03-10 10:41:00 -08:00
2017-03-23 22:46:47 +01:00
For more information on theming and instructions on how to create a custom theme, see the
[theming guide ](./theming.md ).
2017-03-10 10:41:00 -08:00
2017-03-23 22:46:47 +01:00
## Step 5: Gesture Support
2016-08-10 17:10:38 -07:00
2017-03-23 22:46:47 +01:00
Some components (`md-slide-toggle` , `md-slider` , `mdTooltip` ) rely on
2016-12-23 12:11:42 -08:00
[HammerJS ](http://hammerjs.github.io/ ) for gestures. In order to get the full feature-set of these
components, HammerJS must be loaded into the application.
2016-07-04 17:07:48 -07:00
2017-03-23 22:46:47 +01:00
You can add HammerJS to your application via [npm ](https://www.npmjs.com/package/hammerjs ), a CDN
(such as the [Google CDN ](https://developers.google.com/speed/libraries/#hammerjs )), or served
2016-09-27 16:58:55 +01:00
directly from your app.
2016-07-04 17:07:48 -07:00
2017-03-10 10:41:00 -08:00
To install via npm, use the following command:
2016-11-30 18:07:55 -07:00
``` bash
2017-03-10 10:41:00 -08:00
npm install --save hammerjs
2016-11-30 18:07:55 -07:00
```
2017-03-10 10:41:00 -08:00
After installing, import it on your app's root module.
2016-11-30 18:07:55 -07:00
``` ts
import 'hammerjs' ;
```
2017-03-23 22:46:47 +01:00
## Step 6 (Optional): Add Material Icons
2017-04-08 18:10:02 -06:00
If you want to use the `md-icon` component with the official
[Material Design Icons ](https://material.io/icons/ ), load the icon font in your `index.html` .
2017-03-10 10:41:00 -08:00
``` html
< link href = "https://fonts.googleapis.com/icon?family=Material+Icons" rel = "stylesheet" >
```
2017-03-23 22:46:47 +01:00
For more information on using Material Icons, check out the
[Material Icons Guide ](https://google.github.io/material-design-icons/ ).
2017-04-08 18:10:02 -06:00
Note that `md-icon` supports any font or svg icons; using Material Icons is one of many options.
2017-03-10 10:41:00 -08:00
2017-04-08 18:10:02 -06:00
## Appendix: Configuring SystemJS
2017-03-10 10:41:00 -08:00
2017-03-23 22:46:47 +01:00
If your project is using SystemJS for module loading, you will need to add `@angular/material`
2016-11-16 20:10:34 +02:00
to the SystemJS configuration:
``` js
System . config ( {
// existing configuration options
map : {
2017-04-08 18:10:02 -06:00
// ...
2017-03-10 10:41:00 -08:00
'@angular/material' : 'npm:@angular/material/bundles/material.umd.js' ,
2017-04-08 18:10:02 -06:00
// ...
2016-11-16 20:10:34 +02:00
}
} ) ;
```
2016-09-27 16:58:55 +01:00
2017-07-05 16:29:35 -07:00
## Example Angular Material projects
- [material.angular.io ](https://material.angular.io ) -
We build our own documentation with Angular Material!