AngularJS. Equality operator returns true when false

78 Views Asked by At


Have an equality operator in angularJS that is not returning as I should.

example:
The value that comes from the object "data.valuea" is 50.
Have the value that comes from the object "data.valueb" is 200

<p ng-show="{{data.valuea >= data.valueb}}" class="ng-hide premioprogress">OK</p>
<p ng-show="{{data.valuea < data.valueb}}" class="ng-hide premioprogress">Faltam: {{data.valueb - data.valuea}} pts</p>

Am I doing something wrong? Or would a more correct way to do this?

1

There are 1 best solutions below

0
On BEST ANSWER

It's likely that the values are actually strings and not numbers, so JavaScript is doing a string comparison. One way to get around this is to put parseInt() on the scope and use it in your expression...

$scope.parseInt = function (i) {
    return parseInt(i, 10);
};

<p ng-show="parseInt(data.valuea) >= parseInt(data.valueb)"></p>

JSFiddle