Bind class in html page
This is load from the method {{greetUser()}}
This is danger class if has error
Declare class as a variable in component.ts file
public successClass='text-success';
public hasError= true;
Style.css file
.text-success{
color: green;
}
.text-danger{
color: red;
}
Conditional Class Binding[ngClass]
Component.ts file
public hasError= true;
public hasInfo= true;
public dangerClass=true;
public messageClasses={
'text-success': !this.hasError,
'text-info' : this.hasInfo,
'text-danger': this.dangerClass
}
Component.html file