Yes it is possible, consider using attribute directives. For example to apply some class to a div based on some boolean value use this syntax in div:
div [class.some_class]="isActive"
.
If you want to choose it's content based on some value consider using *ngIf
structural directive (or ngSwitch
). For example
<div> <h1 *ngIf="isActive">I'm ActiveM</h1> </div>
Read more here: https://angular.io/guide/attribute-directives
Also if you have list of some classes and correspoding boolean values that define whether the class is used or not in your controller style, then use following:
in your ts file:
this.currentClasses = {
'saveable': this.canSave,
'modified': !this.isUnchanged,
'special': this.isSpecial
};
in template file use ngClass
:
<div [ngClass]="currentClasses">This div is initially saveable, unchanged, and special</div>
Code is from: https://angular.io/guide/template-syntax#ngclass