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.
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.
Share Improve this question asked Jun 22, 2015 at 13:45 PoiroPoiro 1,0114 gold badges11 silver badges20 bronze badges 1 |2 Answers
Reset to default 31Just 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.
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}}
v_value
a string or a number? – Cerbrus Commented Jun 22, 2015 at 13:46