-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
  • 12,589
  • 27
  • 102
  • 186

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
  • 1,871
  • 2
  • 16
  • 25
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
  • 2,913
  • 1
  • 20
  • 39
Dixit Savaliya
  • 573
  • 2
  • 7