Get started with Angular Material 2 using the Angular CLI.
npm install -g angular-cli@webpackng new my-projectThe new command creates a project with a build system for your Angular app.
Angular Material 2 components are set up in separate modules. This allows you to only pull into your app what you need, reducing the size of your app. Components are installed individually. You can see our list of published packages here.
Note that only packages published under the @latest npm tag are officially released.
npm install --save @angular2-material/core @angular2-material/button @angular2-material/cardThe core module is required as a peer dependency of other components
Now you should be able to import the components normally wherever you'd like to use them. Import the components in your application module:
src/app/app.module.ts
import { MdButtonModule } from '@angular2-material/button';
import { MdCardModule } from '@angular2-material/card';
// other imports
@NgModule({
imports: [MdButtonModule, MdCardModule],
...
})For alpha.7, you need to include the overlay styles in your app via a link element. This will
look something like
<link href="vendor/@angular2-material/core/overlay/overlay.css" rel="stylesheet">In future releases, all of the core styles will be combined into a single distributed css file.
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.
- Include the typings for HammerJS in your typescript build (more info on @types)
- If you want to use Material Design icons, load the Material Design font in your
index.html.
md-iconsupports any font icons or svg icons, so this is only one potential option.
src/index.html
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">