Reputation: 1011
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.
Upvotes: 11
Views: 76779
Reputation: 72857
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.
Upvotes: 31
Reputation: 1425
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}}
Upvotes: 7