Here you will install Angular Material in your Angular application.
- Import
MaterialModule
from@angular/material
and use it inside the imports - Since Angular Material depends on animations, the
BrowserAnimationsModule
needs to be included as well.
Since we will also be using flexbox CSS, let's also include the
@angular/flex-layout
library.
npm install @angular/material @angular/flex-layout --save
Modify the following files to use Angular Material and FlexLayout in the application.
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {HttpClientModule} from '@angular/common/http';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { FlexLayoutModule } from '@angular/flex-layout';
import {
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDialogModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatSelectModule,
MatSidenavModule,
MatSlideToggleModule,
MatTabsModule,
MatToolbarModule
} from '@angular/material';
import {AppComponent} from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
BrowserAnimationsModule,
// Material
MatButtonModule,
MatCardModule,
MatCheckboxModule,
MatDialogModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatSelectModule,
MatSidenavModule,
MatSlideToggleModule,
MatTabsModule,
MatToolbarModule,
// Flex-layout
FlexLayoutModule
],
bootstrap: [AppComponent]
})
export class AppModule {}
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
@import "https://fonts.googleapis.com/css?family=Material+Icons";
@import "https://fonts.googleapis.com/css?family=Roboto:400,300";
html, body {
display: flex;
flex-direction: column;
font-family: Roboto, Arial, sans-serif;
margin: 0;
height: 100%;
}
We use flex properties on the html
and body
because they are not part of what markup <app-root>Loading...</app-root>
that Angular bootstraps. This can be easily enough be fixed when bootstraping a component that has body
as selector.
@Component({
selector: 'body',
template: '<h1> {{title}} </h1>'
})
export class AppComponent {
title = 'Angular Material Workshop';
}
We import a prebuilt theme file, read Theming your Angular Material app for more info