- The ngClass too works on the same lines, except that it is used to toggle one or multiple classes. For example, check out the following code:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-ngclassex',
templateUrl: './ngclassex.component.html',
styleUrls: ['./ngclassex.component.css']
})
export class NgclassexComponent implements OnInit {
myvalue : boolean;
constructor() {
this.myvalue = true;
}
ngOnInit() {
}
toggleclass()
{
this.myvalue = !this.myvalue;
}
}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-mytestclass',
templateUrl: './mytestclass.component.html',
styleUrls: ['./mytestclass.component.css']
})
export class MytestclassComponent implements OnInit {
myvalue : boolean;
constructor() {
this.myvalue = true;
}
ngOnInit() {
}
}
/* You can add global styles to this file, and also import other style files */
.myclass1
{
color: yellow;
background-color: red;
font-size: 24px;
}
.myclass2
{
height: 400px;
}