bryan bryan - 1 year ago 94
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 Source

Like this?

<div ng-class="{'dark': name.length > 0, 'white': name.length <= 0}">Hi</div>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download