0

I have such type of condition:

<td ng-repeat="sal in name.salaries" 
    ng-if="name.avalue>sal.annual_value">
       Value must be less than or equal to Balance Amount
</td>

Whats happening in real scenario is

For Eg. name.value=1200 sal.annual_value=42 as its not parseInt thats why its considering 42 > 1200.

How can I parseInt() in AngularJS expression?

2
  • name.avalue in ng-if shouldn't it be name.value like in your eg.? Commented Feb 7, 2017 at 11:09
  • just use simple Number(name.value) Commented Feb 7, 2017 at 11:12

4 Answers 4

5

I would use a scope function to make that verification:

{...}
scope.checkSalaries = function(avalue, annual_value) {
   return avalue > annual_value;
}
{...}

and in html:

<td ng-repeat="sal in name.salaries"
    ng-if="checkSalaries(name.avalue,sal.annual_value)">
       Value must be less than or equal to Balance Amount
</td>
Sign up to request clarification or add additional context in comments.

Comments

4

You can use parseInt within your ng-if:

<td 
    ng-repeat="sal in name.salaries"
    ng-if="parseInt(name.avalue)>parseInt(sal.annual_value)">
        Value must be less than or equal to Balance Amount
</td>

Or you can create a function to check this in your controller:

<td 
    ng-repeat="sal in name.salaries"
    ng-if="isGreater(name.avalue, sal.annual_value)">
        Value must be less than or equal to Balance Amount
</td>

$scope.isGreater = function(val1, val2) {
    return parseInt(val1) > parseInt(val2);
};

Comments

2

If you'd like to use parseInt method in the view you can define a Number $scope in your controller, and then user its built in method parseInt() in the view.

e.g.

Controller:

$scope.number = Number;

View:

<td ng-repeat="sal in name.salaries" ng-if="number.parseInt(name.avalue)>number.parseInt(sal.annual_value)">
Value must be less than or equal to Balance Amount</td>

Comments

1

you can also try :

<td 
    ng-repeat="sal in name.salaries"
    ng-show="isGreater(name.avalue, sal.annual_value)">
        Value must be less than or equal to Balance Amount
</td>

$scope.isGreater = function(val1, val2) {
    return parseInt(val1) > parseInt(val2);
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.