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
  • 20,274
  • 11
  • 84
  • 139

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
  • 39,756
  • 7
  • 56
  • 80
  • 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
  • 2,168
  • 18
  • 26