-1

I'm trying to set css class based on condition from val1 and val2 values. if val2 > val1 set css class has-error

<div class="form-group" ng-class="{'has-error': {{obj.amount2 > obj.amount1}}}">
val 1: {{obj.amount1}}
val 2: {{obj.amount2}}
{{obj.amount2 > obj.amount1}}
  • val 1: 100
  • val 2: 200

this always returns false

user1765862
  • 13,635
  • 28
  • 115
  • 220

2 Answers2

0

Don't use binding to evaluate the object.

<div class="form-group" ng-class="{'has-error': obj.amount2 > obj.amount1}">

OR

<div class="form-group" [class.has-error]="obj.amount2 > obj.amount1">

Hope this helps

James
  • 2,516
  • 2
  • 19
  • 31
0

Try this Code:

<div ng-if="val 2>val 1">
<div class="form-group" ng-class="{'has-error': val 2 > val 1}">
</div>
Najam Us Saqib
  • 3,190
  • 1
  • 24
  • 43
Dixit Savaliya
  • 413
  • 3
  • 7