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 '

39 Best Object Oriented JavaScript Interview Questions and Answers

Most Popular 37 Key Questions for JavaScript Interviews. What is Object in JavaScript? What is the Prototype object in JavaScript and how it is used? What is "this"? What is its value? Explain why "self" is needed instead of "this". What is a Closure and why are they so useful to us? Explain how to write class methods vs. instance methods. Can you explain the difference between == and ===? Can you explain the difference between call and apply? Explain why Asynchronous code is important in JavaScript? Can you please tell me a story about JavaScript performance problems? Tell me your JavaScript Naming Convention? How do you define a class and its constructor? What is Hoisted in JavaScript? What is function overloadin

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 SALVADOR

Angular 2, 4, 5, 6, 7, 8 and 9 Interview Questions and Answers -Books

» Are you preparing for Angular Interview? Buy this book (Including Angular 8, 7, 6, 5,4, 2) Interview Q/A Interview Q/A Interview Q/A Interview Q/A Interview Q/A Interview Q/A Interview Q/A » A Complete Guide Book of Angular 9 This is a concise, complete overview of the key aspects of Angular 9. It is fully up to date with the latest release of Angular. This article provide all the important aspects required for angular developers looking for brief and useful content... Posted In Angular 9 » A Complete Guide Book of Angular 8 This is a concise, complete overview of the key aspects of Angular 9. It is fully up to date with the latest release of Angular. This article provide all the important aspects required for angular developers looking for brief and useful content... Posted In Angular 8 » A Complete Guide Book of Angular 7 This is a concise, complete overview of the key aspects of Angular 7. It is fully up to date with the latest release of Angular. This

25 Best Vue.js 2 Interview Questions and Answers

What Is Vue.js? The Vue.js is a progressive JavaScript framework and used to building the interactive user interfaces and also it’s focused on the view layer only (front end). The Vue.js is easy to integrate with other libraries and others existing projects. Vue.js is very popular for Single Page Applications developments. The Vue.js is lighter, smaller in size and so faster. It also supports the MVVM ( Model-View-ViewModel ) pattern. The Vue.js is supporting to multiple Components and libraries like - ü   Tables and data grids ü   Notifications ü   Loader ü   Calendar ü   Display time, date and age ü   Progress Bar ü   Tooltip ü   Overlay ü   Icons ü   Menu ü   Charts ü   Map ü   Pdf viewer ü   And so on The Vue.js was developed by “ Evan You ”, an Ex Google software engineer. The latest version is Vue.js 2. The Vue.js 2 is very similar to Angular because Evan You was inspired by Angular and the Vue.js 2 components looks like -