Home » Angular » Proper way to Use Angular Material in Angular project

Proper way to Use Angular Material in Angular project

In this article, we going to see how to use Angular Material in your Angular project. Angular Material is created for Angular to minimize the UI works. Using Angular Material components help to build beautiful, compatible, and modern UI components. This will run for all browsers with Mobile and Web applications. Angular Material comes with flexible UI components and responsive design also with fast and optimized for Angular.

Getting Started with Angular App

Before using Angular Material first you need to install the Angular App. The best way to create your Angular project using Command Line Interface (CLI), for that here you have an article for installing an Angular app.

Install Angular Material from NPM in your Angular App

Once you installed the Angular App below you have the command to install Angular Material properly. Use the following steps to build your Angular Material App.

Step 1

The below command helps to install Material, CDK and Animation packages.

Step 2

Once you installed all the packages now import the Material CSS file in your main style.css file. Angular Material providing 4 types of themes that you can use any one style in your application. Below you have the code, use one of the theme in your application.

Step 3

After that import BrowserAnimationsModule in your app.module.ts file. The browser Animations supports Animations in your Angular project.

Step 4

Now the main thing is Material Module, they are various Module in the Angular Material like Buttons, Autocomplete, Checkbox, Datepicker and more. Here we going to use MatButtonModule, use the following command to import MatButtonModule in your app.module.ts file.

Step 5

Install Hammer JS using the below command.

Step 6

Import Hammer JS in your src/main.ts file.

Step 7

Now add the below Material Icons CDN in your index.html which helps to use default Material Design Icons in your Angular Application.

Step 8

After adding the Material Icons CDN, now import MatIconModule in your app.module.ts file.

Step 9

Once you completed all these steps now it is time to add HTML buttons with Angular Material Attribute, which creates beautiful buttons and icons in your Angular App. Add the below code for display buttons and icons.

Execute the Angular App

Now run your application with the ng serve command and see how it looks like, below here you have an example screenshot.

Proper way to Use Angular Material in Angular project

Conclusion:

I hope in this article, you learned step by step to install and configure the Angular Material packages and their dependencies. Here we used only buttons components, in the following articles I show you other components with examples.

Was this article helpful?

Yes No
×

How can we improve it?

×

We appreciate your helpul feedback!

Your answer will be used to improve our content. The more feedback you give us, the better our pages can be.

Follow us on social media:

Facebook Pinterest

Mraj

Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top