bryan bryan - 1 month ago 22
AngularJS Question

Assigning multiple shorthand conditional statements in ng-class

Currently, I have container that gives it a class of dark if the length is greater then 0.

<div ng-class="{dark: name.length > 0}">Hi</div>


Is there a way to add another condition to this? So maybe if not, give it a class of white. Or an entirely different conditional statement to give it a class of white?

Answer

Like this?

<div ng-class="{'dark': name.length > 0, 'white': name.length <= 0}">Hi</div>