0

I have get my number field value from firebase and inject into the table like this:

<td><label>{{obj.mynumber}}</label></td>

mynumber values are like this:

10 000
2 000
10
250 000 000

when I sort the column, it sorts it based on the digits until the first space, which is wrong. So i need to reformat it as a number and remove the spaces. How to achieve this?

1 Answer 1

2

Just create a dedicated filter :

angular.module('filters.stringUtils', [])

.filter('removeSpaces', [function() {
    return function(string) {
        if (!angular.isString(string)) {
            return string;
        }
        return string.replace(/[\s]/g, '');
    };
}])

and call it like :

<td><label>{{obj.mynumber.toString() | removeSpaces}}</label></td>
3
  • I get this error: Error: $parse:syntax Syntax Error
    – cplus
    Commented Jan 19, 2017 at 13:08
  • How to add a dollar sign to the end of it as well? thanks
    – cplus
    Commented Jan 19, 2017 at 15:13
  • Just concate it like {{(obj.mynumber.toString() | removeSpaces) + '$'}}
    – Ankur
    Commented Jan 20, 2017 at 7:08

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.