16 April 2020

NgClass example in angular

  • Open Command prompt and use below commands to create angular project
  • E:
  • cd E:\TestProjects\Angular
  • ng new NgClass-example-in-angular --style=scss --routing --skip-install
  • cd NgClass-example-in-angular 
  • npm install
  • Open project in visual studio code.
  • Open app.component.ts file and update code as below

  • import { Component } from '@angular/core';

    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss']
    })
    export class AppComponent {
    }
  • Open app.component.html file and update code as below

  • <style>
      .first {
        background-color#3471eb;
    }
    </style>
    <h1>NgClass example in angular</h1>
    <div [ngClass]="'first'">
     Example 1
    </div>

    Output:


    No comments:

    Post a Comment