0

Hi I'm using Angular with Twitter Bootstrap. I want to trigger the has-error class with one of the two errors. But neither:

<div class="form-group" ng-class="{'has-error' : errorTime, 'has-error' : errorDate}">

nor:

<div class="form-group" ng-class="{'has-error' : errorTime, errorDate}">

does work.

I thought it would work like this Adding multiple class using ng-class

On the first solution it ignores the second parameter. So if the first is true it triggers has-error no matter what the second parameter is. (I switched them in the code)

Community
  • 1
  • 1
Andi Giga
  • 3,744
  • 9
  • 38
  • 68

1 Answers1

2

ng-class's value is supposed to be an object literal, whose attribute values are boolean. An object may not have the same attribute multiple times. And errorTime, errorDateis not a boolean expression. What you want is simply

{'has-error' : errorTime || errorDate}
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255