1

I have JSON file with a list of strings that contain numbers, e.g

{
    "MyAccount": "105"
}

On the front end, can i perform a condition on this value? ie:

<div ng-if="MyAccount > 100">
   //code ig account greater than 100
</div>

Trying to do this without having to write any JS as this ng-if will be within a complex ng-repeat

Ive tried:

<div ng-if="parseInt(MyAccount) > 100">
   //code ig account greater than 100
</div>
Oam Psy
  • 8,555
  • 32
  • 93
  • 157

1 Answers1

6
<div ng-if="MyAccount > 100">

this should work since javascript can evaluate something like ("6" > 5) to true.

somehow,


you can try something like this,

<div ng-if="myfunc(MyAccount)">

in the controller,

$scope.myfunc = function(myAcc) {
    var intValue = parseInt(myAcc);

    if(intValue > 100) {
        return true;
    } else {
        return false;
    }
}
Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92
  • If I have this, `` this should not work because `MyAccount` is `String`. Can we convert `MyAccount` to `int` inside `ng-click` ? thanks! – Fai Zal Dong Feb 03 '17 at 08:02