Here I want to add CSS classes dynamically to the element using ngClass directive in angular.js.
<p [ngClass]="addClasses()">testing content</p>
and below is my ts code:
isbold: boolean = false;
isItalic: boolean = true;
addClasses() {
let classes = {
boldClass: this.isbold,
italicsClass: this.isItalic
};
return classes;
}
boldClass and italicsClass are two classes in my css file, these classes should apply depending on the value in the corresponding boolean variables. But I'm getting the error as Can not find name for both boldClass and italicsClass. Any help appreciated.
=in an object literal, you use:. SoboldClass: this.isbold, for instance.