2016-09-13 14:44:43 -07:00
|
|
|
Get started with Angular Material 2 using the Angular CLI.
|
2016-05-25 10:10:26 -07:00
|
|
|
|
2016-09-13 14:44:43 -07:00
|
|
|
## Install the CLI
|
2016-05-25 10:10:26 -07:00
|
|
|
|
|
|
|
|
```bash
|
2016-09-19 19:51:44 +03:00
|
|
|
npm install -g angular-cli
|
2016-05-25 10:10:26 -07:00
|
|
|
```
|
|
|
|
|
|
2016-09-13 14:44:43 -07:00
|
|
|
## Create a new project
|
2016-05-25 10:10:26 -07:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
ng new my-project
|
|
|
|
|
```
|
|
|
|
|
|
2016-09-13 14:44:43 -07:00
|
|
|
The new command creates a project with a build system for your Angular app.
|
|
|
|
|
|
2016-09-27 16:58:55 +01:00
|
|
|
## Install Angular Material components
|
2016-05-25 10:10:26 -07:00
|
|
|
|
|
|
|
|
```bash
|
2016-09-27 16:58:55 +01:00
|
|
|
npm install --save @angular/material
|
2016-05-25 10:10:26 -07:00
|
|
|
```
|
|
|
|
|
|
2016-09-27 16:58:55 +01:00
|
|
|
## Import the Angular Material NgModule
|
2016-05-25 10:10:26 -07:00
|
|
|
|
2016-09-13 14:44:43 -07:00
|
|
|
**src/app/app.module.ts**
|
2016-05-25 10:10:26 -07:00
|
|
|
```ts
|
2016-09-27 16:58:55 +01:00
|
|
|
import { MaterialModule } from '@angular/material';
|
2016-09-13 14:44:43 -07:00
|
|
|
// other imports
|
2016-08-09 11:16:08 -07:00
|
|
|
@NgModule({
|
2016-09-27 16:58:55 +01:00
|
|
|
imports: [MaterialModule.forRoot()],
|
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
|
|
|
```
|
|
|
|
|
|
2016-10-25 10:14:30 -07:00
|
|
|
## Include the core and theme styles:
|
|
|
|
|
This is **required** to apply all of the core and theme styles to your application. You can either
|
|
|
|
|
use a pre-built theme, or define your own custom theme.
|
2016-07-04 17:07:48 -07:00
|
|
|
|
2017-01-03 18:22:10 +01:00
|
|
|
:trident: See the [theming guide](./theming.md) for instructions.
|
2016-08-10 17:10:38 -07:00
|
|
|
|
2016-12-23 12:11:42 -08:00
|
|
|
### Additional setup for gestures
|
2017-01-03 18:22:10 +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
|
|
|
|
2016-12-23 12:11:42 -08:00
|
|
|
You can add HammerJS to your application via [npm](https://www.npmjs.com/package/hammerjs), a CDN
|
2016-09-27 16:58:55 +01:00
|
|
|
(such as the [Google CDN](https://developers.google.com/speed/libraries/#hammerjs)), or served
|
|
|
|
|
directly from your app.
|
2016-07-04 17:07:48 -07:00
|
|
|
|
2016-11-30 18:07:55 -07:00
|
|
|
#### If you want to include HammerJS from npm, you can install it:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
npm install --save hammerjs
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-23 12:11:42 -08:00
|
|
|
After installing, import HammerJS on your app's module.
|
2016-11-30 18:07:55 -07:00
|
|
|
**src/app/app.module.ts**
|
|
|
|
|
```ts
|
|
|
|
|
import 'hammerjs';
|
|
|
|
|
```
|
|
|
|
|
|
2016-11-16 20:10:34 +02:00
|
|
|
## Configuring SystemJS
|
|
|
|
|
If your project is using SystemJS for module loading, you will need to add `@angular/material`
|
|
|
|
|
to the SystemJS configuration:
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
System.config({
|
|
|
|
|
// existing configuration options
|
|
|
|
|
map: {
|
|
|
|
|
...,
|
2016-12-23 19:10:34 +01:00
|
|
|
'@angular/material': 'npm:@angular/material/bundles/material.umd.js'
|
2016-11-16 20:10:34 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
2016-10-25 10:14:30 -07:00
|
|
|
### [Optional] Using Material Design icons with `md-icon`:
|
2016-05-25 10:10:26 -07:00
|
|
|
|
2016-10-11 20:48:41 +02:00
|
|
|
- If you want to use Material Design icons in addition to Angular Material components,
|
|
|
|
|
load the Material Design font in your `index.html`.
|
|
|
|
|
`md-icon` supports any font icons or svg icons, so this is only one option for an icon source.
|
2016-05-25 10:10:26 -07:00
|
|
|
|
|
|
|
|
**src/index.html**
|
|
|
|
|
```html
|
|
|
|
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
|
|
|
|
```
|
2016-09-27 16:58:55 +01:00
|
|
|
|
2016-10-11 20:48:41 +02:00
|
|
|
## Sample Angular Material 2 projects
|
2016-09-27 16:58:55 +01:00
|
|
|
- [Material 2 Sample App](https://github.com/jelbourn/material2-app)
|
|
|
|
|
- [Angular Connect 2016 Demo](https://github.com/kara/leashed-in)
|