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
|
|
|
|
2016-10-25 10:14:30 -07:00
|
|
|
:trident: See the [theming guide](docs/theming.md) for instructions.
|
2016-08-10 17:10:38 -07:00
|
|
|
|
2016-10-25 10:14:30 -07:00
|
|
|
### Additional setup for `md-slide-toggle` and `md-slider`:
|
2016-08-09 11:16:08 -07:00
|
|
|
The slide-toggle and slider components have a dependency on [HammerJS](http://hammerjs.github.io/).
|
2016-07-04 17:07:48 -07:00
|
|
|
|
2016-09-27 16:58:55 +01:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
npm install --save-dev @types/hammerjs
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Import HammerJS on your app's module.
|
|
|
|
|
|
|
|
|
|
**src/app/app.module.ts**
|
|
|
|
|
```ts
|
|
|
|
|
import 'hammerjs';
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-06 07:56:04 +01:00
|
|
|
Finally, you need to add `hammerjs` to the `types` section of your `tsconfig.json` file:
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"compilerOptions": {
|
|
|
|
|
"types": [
|
|
|
|
|
"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: {
|
|
|
|
|
...,
|
|
|
|
|
'@angular/material': 'npm:@angular/material/material.umd.js'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
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)
|