Abhishek Kumar Abhishek Kumar - 5 days ago 5
AngularJS Question

Display absolute value angularjs

I am getting a negative number from JSON object. I want to remove "-" form that negative number and only display the absolute value.

Received json:

{
"value": -2.34
}


What I want to show:


The value is: 2.34

Answer

You can use angular filter

js file

angular.module('myApp',[]).filter('makePositive', function() {
    return function(num) { return Math.abs(num); }
});

html file

{{ (-12) | makePositive }}
{{ (2) | makePositive }}

output

12 2

Comments