Introduction
In this article, we will learn how to build Material design with a fonts using Angular and Bootstrap 4. Also, we will learn steps to fix issues in various ways during the installation of the Angular Material package and its use.
Prerequisites
- Node
- Npm
- Angular CLI
- TypeScript
- Visual Studio Code
Note
Before going through this session, please visit my previous articles related to Angular 7 applications.
- Steps To Build 🏗️ Angular 7 (Beta) Desktop 🖥️ Apps With Electron
- Steps To Add 📎 Country Flags 🏁 In Angular App Using Bootstrap 4
Step 1
In this step, you need to install Angular Material, Angular CDK, and Angular Animations. For this, you can use either the npm or yarn command-line tool to install packages. Run the command as mentioned below.
PS C:\Angular7\Dev\angular7app> npm install --save @angular/material @angular/cdk @angular/animations
Step 2
After the animations package is installed, import BrowserAnimationsModule into your project to activate the animations feature support. For this, put the below code in the app.module.ts file to import the animation support in Angular application.
- import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
Then, inside the imports section, add the BrowserAnimationsModule to activate the animation support.
- imports: [
- BrowserModule,
- AppRoutingModule,
- BrowserAnimationsModule,
- AngularFireModule.initializeApp(environment.firebase)
- ],
Step 3
Import the NgModule for each and every component as per your requirement. For the button component, I have added the below code to import MatButtonModule. Repeat the same steps as per step 2.
- import {MatButtonModule} from '@angular/material/button';
Like this, for checkbox component, I have added the below code to import MatCheckboxModule. Repeat the same steps as per step 2.
- import {MatCheckboxModule} from '@angular/material/checkbox';
Step 4
In this step, a theme is required to apply all of the theme styles to our Angular application. For this, add the below line of code in styles.scss file.
- @import "~@angular/material/prebuilt-themes/indigo-pink.css";
Step 5
Then, we need to add HammerJS to your application via npm. Some components depend on HammerJS for gestures. In order to get the full feature-set of these components, HammerJS should be required.
Use the following command to install HammerJS via NPM.
PS C:\Angular7\Dev\angular7app> npm install --save hammerjs
Step 6
After successful installation of HammerJS, import it on app.module.ts file of Angular application. Then put the below code in app.module.ts file of Angular application.
- import 'hammerjs';
Step 7
Here, I need to add mat-icon component with the Material Design Icons. Then, load the icon font in your index.html. It supports any font. To do so, add the below line of code in index.html file.
- <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
Step 8
In this step, I added a checkbox control which is enhanced with Material Design styling and animations. To do so, I opened the app.component.html file and added the below code.
- <mat-checkbox>Check me!</mat-checkbox>
OUTPUT

Step 9
In this step, I added a button control which is enhanced with Material Design styling and ink ripples. To do so, I opened the app.component.html file and added the below code.
- <div class="example-button-row">
- <button mat-raised-button>Basic</button>
- <button mat-raised-button color="primary">Primary</button>
- <button mat-raised-button color="accent">Accent</button>
- <button mat-raised-button color="warn">Warn</button>
- <button mat-raised-button disabled>Disabled</button>
- <a mat-raised-button routerLink=".">Link</a>
- </div>










Floris GroenendijkPosted Jul 16, 2020, 5:08 AM
Your article helped me out, thanks! The command I used was only in the picture though... I used ng add @angular/[email protected] After that I got the hammerjs question...
Chittaranjan SwainPosted Aug 18, 2019, 11:06 PM
Nice article. Good job..
Lucas BaumPosted Aug 12, 2019, 8:35 PM
Nice, said very detailed
Sachin SboaPosted Aug 12, 2019, 2:37 AM
Awesome article and keep sharing....