Many frontend frameworks have a practice of encapsulating their CSS styling by adding another class as a prefix.
For example, in Bootstrap: btn btn-primary
where btn
is the prefix.
If I were to conditionally apply this using [ngClass]
in Angular, it would cause an issue:
<div [ngClass]="{'btn btn-primary': booleanVar, 'btn btn-danger': !booleanVar}"></div>
This problem can be solved easily by extracting the common class like this:
<div class="btn" [ngClass]="{'btn-primary': booleanVar, 'btn-danger': !booleanVar}"></div>
Voilà, now there are no spaces in the conditions and Angular approves.
Now let's apply this concept to Font Awesome icons, where prefixes can be found here.
Style Prefix Example
Solid fas <i class="fas fa-igloo"></i>
Regular far <i class="far fa-igloo"></i>
Light fal <i class="fal fa-igloo"></i>
Brands fab <i class="fab fa-font-awesome"></i>
1st question: Can you use spaces in a conditional query? If so, how?
2nd question: (If the first question is not possible) How would you handle a situation where the prefix is not static (like in the case of Font Awesome)?