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);

Popular posts from this blog

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

55 Best TypeScript Interview Questions and Answers - JavaScript!

What Is TypeScript? By definition, "TypeScript is a typed superset of JavaScript that compiles to plain JavaScript." TypeScript is a superset of JavaScript which provides optional static typing, classes and interfaces. => The TypeScript was first made public in the year 2012. => Typescript is a modern age JavaScript development language. => TypeScript is a strongly typed, object oriented, compiled language. => TypeScript was designed by Anders Hejlsberg (designer of C#) at Microsoft. => TypeScript is both a language and a set of tools. As an Example of TypeScript, class Hello {     msg : string ;      constructor ( message : string ) {          this . msg = message ;      }       getMsg () {          return "Hello, " + this . msg ;      } } TypeScript introduced a great deal...

PHP Frameworks Interview Questions - Yii, Slim, Zend, PHPixie, F3, Aura Frameworks

» Yii 1.0/2.0 Interview Questions The Yii is a pure OOP based framework, free, open source, high-performance, component-based PHP framework for rapidly developing modern Web Applications and the name Yii is pronounced as Yee or [ji:]).... Posted In Yii » Slim Framework Interview Questions Slim Framework is a PHP micro framework that helps PHP developers to write quickly and easily a powerful web applications and APIs. Posted In Slim PHP » PHPixie Framework Interview Questions PHPixie is a Modern, open-source, fast, secure and a lightweight MVC PHP framework designed for speed and simplicity. Posted In PHPixie PHP » Fat Free Framework (F3) Interview Questions A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust web applications - fast! Posted In Fat Free Framework PHP » Aura PHP Framework Interview Questions Aura Framework is a collection of High-quality, well-tested, standards-compliant, decoupled libraries that can be used in any...

.NET Core MVC Interview Questions and Answers

» OOPs Interview Questions Object Oriented Programming (OOP) is a technique to think a real-world in terms of objects. This is essentially a design philosophy that uses a different set of programming languages such as C#... Posted In .NET » .Net Constructor Interview Questions A class constructor is a special member function of a class that is executed whenever we create new objects of that class. When a class or struct is created, its constructor is called. A constructor has exactly the same name as that of class and it does not have any return type… Posted In .NET » .NET Delegates Interview Questions Delegates are used to define callback methods and implement event handling, and they are declared using the "delegate" keyword. A delegate in C# is similar to function pointers of C++, but C# delegates are type safe… Posted In .NET » ASP.Net C# Interview Questions C# was developed by Microsoft and is used in essentially all of their products. It is mainly used for ...

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