But I want somethi...">

AngularJS adds text to ng-bind with filter

I have this code (output = 1,000):

<span ng-bind"item.num | number : 0"></span> 

But I want something like 1000 km. Any way to do this without creating a new interval.

Something like this does not work:

 <span ng-bind"item.num + ' km' | number : 0"></span> 
+7
angularjs filter angular-filters ng-bind
source share
4 answers
 <span ng-bind="(input | filter) + 'km'"></span> 
+8
source share

The syntax for this is:

 <span ng-bind="(item.num | number : 0) + ' km' "></span> 

Working plunkr

+3
source share

As a more general solution, specify a custom JSFiddle filter:

 .filter('formatNumber', function () { return function (input) { return input + 'km'; } }); 

and

 <span ng-bind="item.num | formatNumber"></span> 
+2
source share

You can do this using parentheses.

 <span ng-bind"(item.num | number : 0) + 'km' "></span> 

If the device is always km and not dynamic, you can simply put it in plain text.

 <div><p><span ng-bind"item.num | number : 0"></span>km</p></div> 
0
source share

All Articles