I need to apply a regex to strip all non-digits from an object's value in an ng-repeat.
This is what I'm trying to do:
<span>{{obj.value.replace(/\D/g, '')}}</span>
Any idea on how to do this best?
I need to apply a regex to strip all non-digits from an object's value in an ng-repeat.
This is what I'm trying to do:
<span>{{obj.value.replace(/\D/g, '')}}</span>
Any idea on how to do this best?
You can do it that way, but the best way would probably be to create a custom filter.
app.filter('onlyNumbers', function() {
return function(val) {
return val.replace(/\D/g, '');
};
});
Then:
<span>{{ obj.value | onlyNumbers }}</span>