0

I'm using the [class.*] syntax to apply classes conditionally.
I've found myself wanting to always apply a class.

My current code is as follow:

[class.general]="true"
[class.new]="model.isNew"
[class.edited]="model.isEdited"

The [class.general]="true" is a bit weird and feels like an hack. Is there a standard/better way to have a fixed class while also using conditionals for other classes?

LppEdd
  • 18,845
  • 6
  • 70
  • 121

2 Answers2

0

Just adding to the @yurzui point, If you have multiple classes adding dynamically, I would suggest using ngClass

<div class="general" [ngClass]="{'new': model.isNew, 'edited': model.isEdited}"> 
Sachila Ranawaka
  • 31,266
  • 5
  • 51
  • 75
  • I've considered it, but being a matter of taste, I prefer the `[class]` way. Thanks anyway! – LppEdd Dec 28 '18 at 10:51
0

You can try following ways of assigning class

Abhishek Gangwar
  • 1,780
  • 15
  • 24