This is the second part in a seven-part series about the JavaScript framework, Angular 5.
In this part, we’ll go over adding Angular Material to our application.
This is not intended to be a complete guide, but rather an overview of the basics to get you up and running so you can get to know Angular Material and how to use it with Angular 5.
Article Series:
- Creating Angular 5 application with Angular-cli
- Using
Angular MaterialwithAngular 5(You are here) - Deploy Angular 5 Application to Netlify
- Build
PWAwith Angular 5 App - Build Dynamic themes for
Angular Material - Using
FlexLayoutwith Angular 5 - Building
NewsApp usingAngular 5
Final Demo here
Installing Angular Material
I’ll assume that you checked the previous article in this series and now you have an angular application with routes and sass styling, so let’s get into how to install Angular Material.
In your terminal cd to your application directory and run this line:
Some of the material components use the Angular animation library, which is also installed separately
Now we have to integrate these animations
Open src/app/app.module.ts
Now import the animations and add it to imports in @NgModule.
Here’s the code
Creating Material Module
Now, we have to import the material components we want to use. and import them into the imports array of ngModule.
But the material components are too much, so I prefer creating a custom module specifically for our material component imports. Name it material.module.ts
Create a new file src/app/material.app.ts and paste the following code.
Here, we only including most of the components in Angular Material I know that it’s not the best practice to include all these components. But I prefer to include most of material components so I don’t have to add them myself later. I know that I’m too lazy 😎.
Next, we have to import material.module.ts into our app.module.ts.
Theming
Next, we want to add a theme to our material.
Open /src/styles.scss and paste the following line
Now, we need to include *HammerJS for gesture support.
In your terminal, type:
We have to include it, open /src/main.ts
Material Design Icons
One last thing to go, we have to add the Material Design Icons
in /src/index.html add the following line before </head>
Simple Material Example
Let’s edit our previous html code, open /src/app/app.component.html and edit it like the following code.
I just added some material components like (toolbar, button etc..) You can check the documentation here
We have to add some css to make our page look better,
open /src/styles.scss and add the following code:
also /src/app/app.component.scss
Check your page now, it should look like this:

Let’s make it more complex and create a component for our home page to display some material components.
But this time I have to mention something as I know you might face a problem while using it.
Now we have 2 modules in our application ( app.module.ts and material.module.ts), so if you want to create new component or service you have to mention where do you want to add your new component.
Let’s see a practical example.
in your terminal run( make sure you’re in your root directory first):
This will create new component named home and will add it to app.module.ts.
First let’s add new route for our home component.
Open /src/app/app-routing.module.ts. You have to import home component and add it to routes.
Now you should see home works! in your browser.
Next I want to add some cool material components.
Open /src/app/home/home.component.html
I removed the repeated code for brevity you can add it yourself.
and to create the grid I added the following code in /src/app/home/home.component.scss
Here’s the result

Next: Deploy Angular 5 Application to Netlify
Some useful Links:
- 👨️ My Website/Portfolio
- 🔥 Get your $50 in FREE hosting credit HERE
- 🤑️ No Stripe? How To Get Paid With Payoneer ⇒ $25 + $10 Sign UP Bonus