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>
1

4 Answers 4

9
<span ng-bind="(input | filter) + 'km'"></span>
Sign up to request clarification or add additional context in comments.

Comments

3

The syntax for this is :

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

Working Plunkr

Comments

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>

1 Comment

it could be done on HTML would be more better using number filter itself like this stackoverflow.com/a/31923315/2435473
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>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.