Angular + Material | How to Install Angular Material in Angular Project

In this tutorial, we will go through quick steps to Install Angular Material in Angular project and also discuss how to add themes and different Material Components in an Angular project.

Angular Material is a UI framework based on Material concepts of designs. It is a mobile-first framework properly built for Angular. The material provides a number of easy to add and use flexible UI web components, which works mailing on different device screen sizes.

To start the Material installation, first, we will create a new Angular project using Ng CLI tool using Command prompt terminal.

Make sure you have NodeJS installed to use NPM which Node Package Manager used to install packages directly from the terminal.

Install Ng CLI

Angular/NG CLI tool makes Angular development very easy by providing easy commands to generate services, components, directive, etc.

Run following CMD command to install CLI tool

Create a new Angular Project

As now we have NG CLI tool install, we can easily create a new Angular project by running following command in CLI

After running above command it will ask if you want Routing in the project? and also about CSS style formats you want to opt for the project.

Install Angular Material

To install Angular Material in Angular project run following npm CLI command to install Material, CDK and Animation packages.

Enable Animation for Material Components

Animations like smooth scrolling effect, ripple effect on button click need to be enabled or disabled by importing following modules.

In the app.module.ts file make the following changes:

Enable Animations:

Disable Animations:

Add Material Theme

Components used in the project are styles using CSS available in the material CSS theme file, so just add the following theme file link in styles.css available at the project root.

you can use any one of these available themes.

That’s it … we are done with Angular material configuration.

How to use Material Components?

To use an Angular Material component like buttons, autocomplete, tabs, etc, first you need to add their modules in your project’s app.module.ts file. So that they will be available to every component under that module.

For example, if you want to use Material Buttons, import MatButtonModule then add in the imports array.

 

Thanks for visiting :) Let me know if you have some suggestions or feedback for this post in the comment section. Looking for any tutorial or demo on FreakyJolly, just drop me a message here

Leave a Reply

avatar
  Subscribe  
Notify of