MaterialModule is deprecated in version 2.0.0-beta.3 and has been completely removed in version 2.0.0-beta.11. See this CHANGELOG for more details. Please go through the latest changes.
Breaking changes
- Angular Material now requires Angular 4.4.3 or higher
- MaterialModule has been removed.
- For beta .11, we decided to completely abandon the "md" prefix and use "mat" to move forward.
Please go through CHANGELOG, we will get more answers!
An example is shown below cmd
npm install --save @angular/material @angular/animations @angular/cdk npm install --save angular/material2-builds angular/cdk-builds
Create a file (material.module.ts) in the "app" folder
import { NgModule } from '@angular/core'; import { MatButtonModule, MatMenuModule, MatToolbarModule, MatIconModule, MatCardModule } from '@angular/material'; @NgModule({ imports: [ MatButtonModule, MatMenuModule, MatToolbarModule, MatIconModule, MatCardModule ], exports: [ MatButtonModule, MatMenuModule, MatToolbarModule, MatIconModule, MatCardModule ] }) export class MaterialModule {}
import to app.module.ts
import { MaterialModule } from './material.module';
Your component html file
<div> <mat-toolbar color="primary"> <span><mat-icon>mood</mat-icon></span> <span>Yay, Material in Angular 2!</span> <button mat-icon-button [mat-menu-trigger-for]="menu"> <mat-icon>more_vert</mat-icon> </button> </mat-toolbar> <mat-menu x-position="before" #menu="matMenu"> <button mat-menu-item>Option 1</button> <button mat-menu-item>Option 2</button> </mat-menu> <mat-card> <button mat-button>All</button> <button mat-raised-button>Of</button> <button mat-raised-button color="primary">The</button> <button mat-raised-button color="accent">Buttons</button> </mat-card> <span class="done"> <button mat-fab> <mat-icon>check circle</mat-icon> </button> </span> </div>
Add global CSS 'style.css'
@import 'https://fonts.googleapis.com/icon?family=Material+Icons'; @import ' ~@angular /material/prebuilt-themes/indigo-pink.css';
Your CSS component
body { margin: 0; font-family: Roboto, sans-serif; } mat-card { max-width: 80%; margin: 2em auto; text-align: center; } mat-toolbar-row { justify-content: space-between; } .done { position: fixed; bottom: 20px; right: 20px; color: white; }
If someone didn’t get the output, use the instruction below
Instead of the above interface (material.module.ts), you can directly use the code below in app.module.ts as well.
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MdButtonModule, MdCardModule, MdMenuModule, MdToolbarModule, MdIconModule, MatAutocompleteModule, MatInputModule,MatFormFieldModule } from '@angular/material';
So in this case you do not want to import
import { MaterialModule } from './material.module';
in app.module.ts