Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular filter to replace all underscores to spaces

Tags:

I need a filter to replace all the underscores to spaces in a string

like image 522
Ayeye Brazo Avatar asked Aug 11 '15 10:08

Ayeye Brazo


1 Answers

string.replace not only accepts string as first argument but also it accepts regex as first argument. So put _ within regex delimiters / and aslo add g modifier along with that. g called global modifier which will do the replacement globally.

App.filter('underscoreless', function () {   return function (input) {       return input.replace(/_/g, ' ');   }; }); 
like image 146
Avinash Raj Avatar answered Oct 04 '22 02:10

Avinash Raj