0

I know similar question have been asked before and I have gone through many but not getting the class to be applied.

I have the following:

data-ng-class="doc.documentCategory ? doc.documentCategory.toLowerCase() : '' "

Trying to apply a class depending on the value of the doc.documentary variable. I have tried:

   data-ng-class="[doc.documentCategory ? doc.documentCategory.toLowerCase() : '']"
    data-ng-class="{doc.documentCategory ? doc.documentCategory.toLowerCase() : ''}"

and read: dynamic classname Angular class name variable changing class name based on variable

and others. Appreciate any suggestions.

Community
  • 1
  • 1
Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37

3 Answers3

0

Try this:

ng-class="{'Class1': doc.documentCategory == doc.documentCategory.toLowerCase()}"

The class will be only applied when the condition is true.

Janak
  • 4,986
  • 4
  • 27
  • 45
0

Ended up using the following:

data-ng-class="doc.documentCategory ? doc.documentCategory.toLowerCase() : ''"

It worked !

Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37
-1

Is this angularjs, or angular 2/4? There is some ambiguity because of the linked answers.

If the latter, then [ngClass] = "doc.documentCategory ? doc.documentCategory.toLowerCase() : ''" should work?

mikegeyser
  • 327
  • 1
  • 6