11

I'm trying to remove a period '.' from a value that comes from a feed, however I don't really want to do this in my app.js, rather in my view.

So if I do the following:

 value: {{item.v_value}}

I get 3.5, I'd simply like to strip out and render out 35 instead.

So basically reusing the replace function - but on the item value only.

1
  • Is v_value a string or a number? Commented Jun 22, 2015 at 13:46

2 Answers 2

31

Just use replace:

If v_value is a string:

value: {{item.v_value.replace('.', '')}}

If v_value is a number, "cast" it to a string first:

value: {{(item.v_value + '').replace('.', '')}}

Basically, you can use JavaScript in those brackets.

Sign up to request clarification or add additional context in comments.

1 Comment

It almost works for me, I needed to replace all occurrences of that 'dot' so I had to perform a global replacement (\g) and escape the '.' character, like so: {{item.v_value.replace(/\./g, '')}}
7

If you need it to be reusable you can use a filter.

myApp.filter('removeString', function () {
    return function (text) {
        var str = text.replace('thestringtoremove', '');
        return str;
    };
});

Then in your HTML you can something like this:

value: {{item.v_value | removeString}}

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.