0

I have the following code --

    <td ng-class="{danger:values.capacity>threshold}">{{values.capacity}}</td>

The problem is that values.capacity has is a string ("70%") and threshold is an int (70). Is there any way I can make the conversion in the HTML?

1
  • 3
    HTML has no concept of data types. What you're really asking "How do I do this with angular and/or javascript". Commented Jun 17, 2015 at 12:06

1 Answer 1

2

You could use the parseInt() function to convert the 70% to 70 (int).

just call in your controller:

$scope.values.capacity = parseInt($scope.values.capacity, 10); 
Sign up to request clarification or add additional context in comments.

2 Comments

Setting radix 10 explicitly would be better for old browsers: parseInt(str,10)
Yeah if you need to support < IE8 you should use the radix parameter. I have edited my answer

Your Answer

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