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

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...

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 ...

React Lifecycle Components | Mounting, Updating, Unmounting

In React, each component has a life-cycle which manipulate during its three main phases. The following three phases are: 1.       Mounting 2.       Updating 3.       Unmounting React does so by “ Mounting ” (adding nodes to the DOM), “ Unmounting ” (removing them from the DOM), and “ Updating ” (making changes to nodes already in the DOM). Mounting - Lifecycle Phase 1 Mounting is used for adding nodes (elements) to the DOM. The React has four built-in methods that gets called, in this order, when mounting a component - 1.       constructor() 2.       getDerivedStateFromProps() 3.       render() 4.       componentDidMount() Note – 1)       The render() method is required and It always be called and the others methods are optional (you will call...

Angular 8, 7, 6, 5, 4, 2 - Open and Close Modal Popup Using Typescript and Bootstrap

How to Create a Modal Popup for Angular? Two ways to CREAT Modal Popup Window - 1.       Modal Popup using Typescript and Bootstrap 2.       Modal Popup using Angular Material Dialogue Open Modal Popup Using Typescript and Bootstrap – Download and use the Bootstrap CDN to deliver Bootstrap's compiled CSS and JS to your project. Steps 1 – Add Bootstrap CSS and Js files in the AppComponent.HTML file. < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"   crossorigin = "anonymous" > < script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"   crossorigin = "anonymous" ></ script > You can also Install Bootstrap from NPM – npm install bootstrap – save Steps 2 – Add Style CSS for Login and Popup validations and it looks like. .ng-valid[ required ], .ng-valid.required   {  ...

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...