Skip to main content

Angular 5 Material Tutorials - Install Material and CDK

Install CLI -
npm install -g @angular/cli

And it looks like –
D:\Angular\AngularMaterial>npm install -g @angular/cli
[            ......] \ remove:@ngtools/webpack: sill remove C:\Users\Viaindia\AppData\Roaming\npm\node_modules\@angular\[            ......] - finalize:y18n: sill finalize C:\UsC:\Users\Viaindia\AppData\Roaming\npm\ng -> C:\Users\Viaindia\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\@angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/cli@1.7.3
added 60 packages, removed 265 packages, updated 115 packages and moved 10 packages in 85.446s


Install in in your project directory –
ng new ng5material

Here ng5material is a project name and it looks like –
D:\Angular\AngularMaterial>ng new ng5material
  create ng5material/e2e/app.e2e-spec.ts (293 bytes)
  create ng5material/e2e/app.po.ts (208 bytes)
  create ng5material/e2e/tsconfig.e2e.json (235 bytes)
  create ng5material/karma.conf.js (923 bytes)
  create ng5material/package.json (1296 bytes)
  create ng5material/protractor.conf.js (722 bytes)
  create ng5material/README.md (1027 bytes)
  create ng5material/tsconfig.json (363 bytes)
  create ng5material/tslint.json (3012 bytes)
  create ng5material/.angular-cli.json (1246 bytes)
  create ng5material/.editorconfig (245 bytes)
  create ng5material/.gitignore (544 bytes)
  create ng5material/src/assets/.gitkeep (0 bytes)
  create ng5material/src/environments/environment.prod.ts (51 bytes)
  create ng5material/src/environments/environment.ts (387 bytes)
  create ng5material/src/favicon.ico (5430 bytes)
  create ng5material/src/index.html (298 bytes)
  create ng5material/src/main.ts (370 bytes)
  create ng5material/src/polyfills.ts (3114 bytes)
  create ng5material/src/styles.css (80 bytes)
  create ng5material/src/test.ts (642 bytes)
  create ng5material/src/tsconfig.app.json (211 bytes)
  create ng5material/src/tsconfig.spec.json (283 bytes)
  create ng5material/src/typings.d.ts (104 bytes)
  create ng5material/src/app/app.module.ts (316 bytes)
  create ng5material/src/app/app.component.html (1141 bytes)
  create ng5material/src/app/app.component.spec.ts (986 bytes)
  create ng5material/src/app/app.component.ts (207 bytes)
  create ng5material/src/app/app.component.css (0 bytes)

added 1273 packages in 53.495s
'git' is not recognized as an internal or external command,
operable program or batch file.
Project 'ng5material' successfully created.

Install Angular Material in your project directory–
npm install --save @angular/material @angular/cdk

And it looks like –
D:\Angular\AngularMaterial>cd ng5material
D:\Angular\AngularMaterial\ng5material>npm install --save @angular/material @angular/cdk
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/cdk@5.2.4
+ @angular/material@5.2.4
added 2 packages in 10.765s

Install Angular Animations in your project directory–
npm install --save @angular/animations

And it looks like -
D:\Angular\AngularMaterial\ng5material>npm install --save @angular/animations
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/animations@5.2.8
updated 1 package in 10.011s

Create model in your project src folder –
ng g module ngmaterial

And it looks like –
D:\Angular\AngularMaterial\ng5material> ng g module ngmaterial
  create src/app/ngmaterial/ngmaterial.module.ts (194 bytes)


Create component in your project src folder –
ng g component InputFormMaterial

And it looks like –
D:\Angular\AngularMaterial\ng5material>ng g component InputFormMaterial
  create src/app/input-form-material/input-form-material.component.html (38 bytes)
  create src/app/input-form-material/input-form-material.component.spec.ts (707 bytes)
  create src/app/input-form-material/input-form-material.component.ts (319 bytes)
  create src/app/input-form-material/input-form-material.component.css (0 bytes)
  update src/app/app.module.ts (643 bytes)

Run your project using –
ng server --open

And it looks like –
D:\Angular\AngularMaterial\ng5material>ng server --open
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
 11% building modules 15/16 modules 1 active ...modules\style-loader\lib\addStyles.jswebpack: wait until bundle finished: /                                Date: 2018-03-10T05:12:47.547Z
Hash: bdfa3a9fb554876f6fd2
Time: 10838ms
chunk {inline} inline.bundle.js (inline) 3.85 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 21.4 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 549 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 41.5 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 14.6 MB [initial] [rendered]

webpack: Compiled successfully.


Finally set your ngmaterial.module.ts -
import {CdkTableModule} from '@angular/cdk/table';
import {HttpClientModule} from '@angular/common/http';
import {NgModule} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http';
import {
  MatAutocompleteModule,
  MatButtonModule,
  MatButtonToggleModule,
  MatCardModule,
  MatCheckboxModule,
  MatChipsModule,
  MatDatepickerModule,
  MatDialogModule,
  MatDividerModule,
  MatExpansionModule,
  MatGridListModule,
  MatIconModule,
  MatInputModule,
  MatListModule,
  MatMenuModule,
  MatNativeDateModule,
  MatPaginatorModule,
  MatProgressBarModule,
  MatProgressSpinnerModule,
  MatRadioModule,
  MatRippleModule,
  MatSelectModule,
  MatSidenavModule,
  MatSliderModule,
  MatSlideToggleModule,
  MatSnackBarModule,
  MatSortModule,
  MatStepperModule,
  MatTableModule,
  MatTabsModule,
  MatToolbarModule,
  MatTooltipModule,
} from '@angular/material';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {InputFormMaterialComponent} from '../input-form-material/input-form-material.component';

@NgModule({
  exports: [
    CdkTableModule,
    MatAutocompleteModule,
    MatButtonModule,
    MatButtonToggleModule,
    MatCardModule,
    MatCheckboxModule,
    MatChipsModule,
    MatStepperModule,
    MatDatepickerModule,
    MatDialogModule,
    MatDividerModule,
    MatExpansionModule,
    MatGridListModule,
    MatIconModule,
    MatInputModule,
    MatListModule,
    MatMenuModule,
    MatNativeDateModule,
    MatPaginatorModule,
    MatProgressBarModule,
    MatProgressSpinnerModule,
    MatRadioModule,
    MatRippleModule,
    MatSelectModule,
    MatSidenavModule,
    MatSliderModule,
    MatSlideToggleModule,
    MatSnackBarModule,
    MatSortModule,
    MatTableModule,
    MatTabsModule,
    MatToolbarModule,
    MatTooltipModule,
  ]
})
export class MaterialAppModule { }


app.module.ts –
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import {HttpClientModule} from '@angular/common/http';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {HttpModule} from '@angular/http';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MaterialAppModule} from '../app/ngmaterial/ngmaterial.module'
import { AppComponent } from './app.component';
import {InputFormMaterialComponent} from '../app/input-form-material/input-form-material.component';

@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    MaterialAppModule ,
    FormsModule,
    HttpModule,
    HttpClientModule, 
    ReactiveFormsModule 
  ],
  providers: [],
  entryComponents: [InputFormMaterialComponent],
  declarations: [InputFormMaterialComponent],
  bootstrap: [InputFormMaterialComponent]
})
export class AppModule { }

platformBrowserDynamic().bootstrapModule(AppModule);

By Anil Singh | Rating of this article (*****)

Popular posts from this blog

nullinjectorerror no provider for httpclient angular 17

In Angular 17 where the standalone true option is set by default, the app.config.ts file is generated in src/app/ and provideHttpClient(). We can be added to the list of providers in app.config.ts Step 1:   To provide HttpClient in a standalone app we could do this in the app.config.ts file, app.config.ts: import { ApplicationConfig } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; import { provideClientHydration } from '@angular/platform-browser'; //This (provideHttpClient) will help us to resolve the issue  import {provideHttpClient} from '@angular/common/http'; export const appConfig: ApplicationConfig = {   providers: [ provideRouter(routes),  provideClientHydration(), provideHttpClient ()      ] }; The appConfig const is used in the main.ts file, see the code, main.ts : import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from ...

List of Countries, Nationalities and their Code In Excel File

Download JSON file for this List - Click on JSON file    Countries List, Nationalities and Code Excel ID Country Country Code Nationality Person 1 UNITED KINGDOM GB British a Briton 2 ARGENTINA AR Argentinian an Argentinian 3 AUSTRALIA AU Australian an Australian 4 BAHAMAS BS Bahamian a Bahamian 5 BELGIUM BE Belgian a Belgian 6 BRAZIL BR Brazilian a Brazilian 7 CANADA CA Canadian a Canadian 8 CHINA CN Chinese a Chinese 9 COLOMBIA CO Colombian a Colombian 10 CUBA CU Cuban a Cuban 11 DOMINICAN REPUBLIC DO Dominican a Dominican 12 ECUADOR EC Ecuadorean an Ecuadorean 13 EL SALVA...

How To convert JSON Object to String?

To convert JSON Object to String - To convert JSON Object to String in JavaScript using “JSON.stringify()”. Example – let myObject =[ 'A' , 'B' , 'C' , 'D' ] JSON . stringify ( myObject ); ü   Stayed Informed –   Object Oriented JavaScript Interview Questions I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

Encryption and Decryption Data/Password in Angular

You can use crypto.js to encrypt data. We have used 'crypto-js'.   Follow the below steps, Steps 1 –  Install CryptoJS using below NPM commands in your project directory npm install crypto-js --save npm install @types/crypto-js –save After installing both above commands it looks like  – NPM Command  1 ->   npm install crypto-js --save NPM Command  2 ->   npm install @types/crypto-js --save Steps 2  - Add the script path in “ angular.json ” file. "scripts" : [                "../node_modules/crypto-js/crypto-js.js"               ] Steps 3 –  Create a service class “ EncrDecrService ” for  encrypts and decrypts get/set methods . Import “ CryptoJS ” in the service for using  encrypt and decrypt get/set methods . import  {  Injectable  }  from ...

Angular Testing Questions and Answers | 9, 8, 7, 6

What Is Testing? The testing is a tools and techniques for a unit and integration testing Angular applications . Why Test? Tests are the best ways to prevent software bugs and defects. How to Setup Test in Angular Project? Angular CLI install everything you need to test an Angular application. This CLI command takes care of Jasmine and karma configuration for you. Run this CLI command- ng test The test file extension must be “.spec.ts” so that tooling can identify the test file. You can also unit test your app using other testing libraries and test runners. Types of Test – The all great developer knows his/her testing tools use. Understanding your tools for testing is essential before diving into writing tests. The Testing depends on your project requirements and the project cost. The types of Testing looks like - 1.       Unit Test 2.       Integration Test 3.       En...