Getting started with Material Design 6 in Angular 6

Getting started with Material Design 6 in Angular 6

In this post we will give you information about Getting started with Material Design 6 in Angular 6. Hear we will give you detail about Getting started with Material Design 6 in Angular 6And how to use it also give you demo for it if it is necessary.

In this first part of a tutorial series to get started with Material Design 6 in Angular 6, we are going to cover how to install and add support for Material 6 to an Angular 6 project, generated using the Angular CLI 6.

Getting Started

First of all, make sure you have created an Angular 6 project using the Angular CLI 6.

Then use your terminal or command prompt to install the required npm package to add support for Angular Material 6.

npm install --save @angular/cdknpm install --save @angular/material

Next you’ll need to add the Angular Material Module to your app module app.module.ts

So start by importing it:

import{MaterialModule}from'@angular/material';

Then simply add it to the imports array:

@NgModule({declarations:[AppComponent],imports:[BrowserModule,MaterialModule],providers:[],bootstrap:[AppComponent]})exportclassAppModule{}

Some components depend on hammerjs so you need also to install these dependencies:

npm install --save hammerjs  npm install --save-dev @types/hammerjs

Then make sure to import hammer in app.module.ts

import'hammerjs';

Next open tsconfig.app.json and add hammerjs to types array:

"types":["hammerjs"]

There is one more little thing that you need to do to make Material Design 6 work properly.

Open your project styles.css and import the Roboto font and Material icons then set Roboto as the font for body element:

@import'~https://fonts.googleapis.com/icon?family=Material+Icons';@import'~https://fonts.googleapis.com/icon?family=Roboto';body{font-family:Roboto;}

That’s because Material 6 components depend on these resources.

Adding a theme

Before using the Material components, we need to add a theme. There are many built in themes available with the default installation of Angular Metarial2 that are available from /node_modules/angular/material/prebuilt-themes/ folder.

Make sure to look there for all available themes then choose one an import it in project styles.css file:

@import'~@angular/material/prebuilt-themes/indigo-pink.css';

Now you are good to go!

Testing with Material Card Component

If you have successfully installed and configured Material2, you can now test some of its components to make sure everything is ok.

Open app.component.html then add these examples:

<md-card><md-card-header>Example MD Card</md-card-header><buttonmd-button>A Button </button><buttonmd-raised-button>Another Button </button><buttonmd-raised-buttoncolor="primary">A 3rd Button</button><buttonmd-raised-buttoncolor="accent">The 4th Button</button><md-card-footer><buttonmd-fab><md-icon>add circle</md-icon></button></md-card-footer></md-card>

Conclusion

That’s all for this first part, we have seen how to install and setup the required packages to work with Material Design in Angular 6.

On this next part we are going to see some examples so stay tunned!


Hope this code and post will helped you for implement Getting started with Material Design 6 in Angular 6. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US