7

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>
Doug E Fresh
  • 820
  • 8
  • 22
Christopher
  • 3,379
  • 7
  • 25
  • 36
  • 1
    possible duplicate of [Add more text after using a filter in ng-bind in angularjs](http://stackoverflow.com/questions/24463473/add-more-text-after-using-a-filter-in-ng-bind-in-angularjs) – Doug E Fresh Aug 10 '15 at 15:34

4 Answers4

9
<span ng-bind="(input | filter) + 'km'"></span>
Filip Cornelissen
  • 3,682
  • 3
  • 31
  • 41
André Tiago
  • 131
  • 2
3

The syntax for this is :

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

Working Plunkr

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
Pierre-Alexandre Moller
  • 2,354
  • 1
  • 20
  • 29
2

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>
Joy
  • 9,430
  • 11
  • 44
  • 95
  • it could be done on HTML would be more better using `number` filter itself like this http://stackoverflow.com/a/31923315/2435473 – Pankaj Parkar Aug 10 '15 at 15:23
1

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>
Doug E Fresh
  • 820
  • 8
  • 22