Get started with Angular Material 2 using the Angular CLI.
npm install -g angular-cli
ng new my-project
The new command creates a project with a build system for your Angular app.
npm install --save @angular/material
src/app/app.module.ts
import { MaterialModule } from '@angular/material';
// other imports
@NgModule({
imports: [MaterialModule.forRoot()],
...
})
export class PizzaPartyAppModule { }
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.
🔱 See the theming guide for instructions.
The slide-toggle and slider components have a dependency on HammerJS.
Add HammerJS to your application via npm, a CDN (such as the Google CDN), or served directly from your app.
If your project is using SystemJS for module loading, you will need to add @angular/material
to the SystemJS configuration:
System.config({
// existing configuration options
map: {
...,
'@angular/material': 'npm:@angular/material/material.umd.js'
}
});
- 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.
src/index.html
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">