AngularJS append text to ng-bind with filter
10,844
Solution 1
<span ng-bind="(input | filter) + 'km'"></span>
Solution 2
The syntax for this is :
<span ng-bind="(item.num | number : 0) + ' km' "></span>
Solution 3
As a more generic solution, specify a custom filter JSFiddle:
.filter('formatNumber', function () {
return function (input) {
return input + 'km';
}
});
And:
<span ng-bind="item.num | formatNumber"></span>
Solution 4
You can do this by using parenthesis.
<span ng-bind"(item.num | number : 0) + 'km' "></span>
If the unit is always km and is not dynamic, you can just put it in the regular text.
<div><p><span ng-bind"item.num | number : 0"></span>km</p></div>
Author by
Christopher
Updated on June 12, 2022Comments
-
Christopher almost 2 years
I have this code (output=1,000):
<span ng-bind"item.num | number : 0"></span>
But i want something like 1,000 km. Any way to do this without create a new span.
Something like this isn't working:
<span ng-bind"item.num + ' km' | number : 0"></span>
-
Pankaj Parkar over 8 yearsit could be done on HTML would be more better using
number
filter itself like this stackoverflow.com/a/31923315/2435473