Getting Started With Angular Material
Published: 2021-09-10 19:23:36

A lot of developers are using Angular Material in their Angular applications. But what is the best way to add the library, and why do you want to use 

![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## Table Of Contents

-  [What Is Angular Material?](#what-is-angular-material) 
-  [Why Use Angular Material?](#why-use-angular-material) 
-  [How To Add Angular Material?](#how-to-add-angular-material) 
-  [How To Use Angular Material?](#how-to-use-angular-material) 
-  [How To Load All Angular Material Components At Once](#how-to-load-all-angular-material-components-at-once) 

![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## What Is Angular Material?

![Screenshot_2021-09-02_at_15.59.01.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1631300625484/dmyoLS4_h.png)

Angular Material is an Angular Component library build and maintained by Google.

It's a component library filled with a ton of easy to use Angular components. The library includes components like a [datepicker](https://material.angular.io/components/datepicker/overview), [input elements](https://material.angular.io/components/input/overview), [toggle switches](https://material.angular.io/components/slide-toggle/overview), [tables](https://material.angular.io/components/table/overview) and, [a lot more](https://material.angular.io/components/categories).

Components support customization in various ways. You can use their pre-built themes or build your own with the custom color scheme.


![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## Why Use Angular Material?

Angular Material is updated simultaneously with Angular, which is one of the best advantages of using Angular Material and not other component libraries. Every time Google brings a new update for Angular, it will update Angular Material simultaneously.

When you update your Angular application with `ng update`, it will also update Angular Material simultaneously, which is pretty handy.

With Angular Material, you know for sure, as long as Google keeps developing Angular, it will stay Angular Material up-to-date. 

All the components have been tested for a long time. I've been an Angular Material user for a long time, but I've never had an actual error in an Angular Material component.

But if you don't like the style of Angular Material, you can also change their styling. Picking another Angular component library is an excellent alternative if you want something different.


![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## How To Add Angular Material?

Before installing Angular Material in an existing project, we have to make sure you installed the Angular CLI. If you haven't, run this command.

```bash
npm install -g @angular/cli
```

Let's start with installing Angular Material in an existing project.

```bash
ng add @angular/material
```

When you perform the command above, you will get a few configuration options to choose from. Make the choice you want.

After this process, you can use Angular Material in your Angular project.


![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## How To Use Angular Material?

Angular Material components can be used by importing the module.

For example, if you want to use the [checkbox component](https://material.angular.io/components/checkbox/overview), you have to import the following module in the `app.module.ts` if you're going to use it in all the components across the entire application.

```tsx
import {MatCheckboxModule} from '@angular/material/checkbox';
```

This code can be found on every component page in the API tab.

Now you can go to a component where you want to use your imported component. Check the examples tab for an example of the components and code sample's on how to use the component.

```html
<mat-checkbox class="example-margin" [(ngModel)]="checked">Checked</mat-checkbox>
```

![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## How To Load All Angular Material Components At Once

There is no default way to load all Angular Material component modules at once. I think there is a good reason for that.

You can create an Angular Module to import all the Angular Material modules and import that module in your `app.module.ts`. 

The question is, are you going to use all the Angular Material components in your application? I don't think so because you're going to waste a whole lot of data that the user needs to download.

I think it's wiser to load the module of the Angular Material component in the Angular Module where you need it. And not load them all at once.

But if you want to do it, check out this [Gist on Github](https://gist.github.com/pimatco/d5b1891feb90b60ca4681011b6513873) which has all the available Angular Material modules for you.

{% gist https://gist.github.com/pimatco/d5b1891feb90b60ca4681011b6513873 %}


![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## Conclusion

Angular Material offers a great set of well-tested and configurable Angular components. The most significant benefit is, it's developed simultaneously by the Angular team.

I'm looking forwards to see all the projects you build with Angular Material!

![divider-byrayray.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629890886208/NhHYvPmBA.png)

## Thanks!
![hashnode-footer.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1629789655319/nBF6anHH4w.png)
*I hope you learned something new or are inspired to create something new after reading this story! 🤗 If so, consider subscribing via email (scroll to the top of this page) or follow me here on Hashnode.
*

> Did you know that you can create a [Developer blog like this one, yourself](https://hashnode.com/@devbyrayray/joinme)? It's entirely for free. 👍💰🎉🥳🔥

*If I left you with questions or something to say as a response, scroll down and type me a message. Please send me a [DM on Twitter @DevByRayRay](https://twitter.com/@devbyrayray) when you want to keep it private. My DM's are always open 😁*