Angular filter to replace all underscores to spaces

前端 未结 6 1366
感动是毒
感动是毒 2020-12-18 18:10

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

6条回答
  •  忘掉有多难
    2020-12-18 18:52

    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, ' ');
      };
    });
    

提交回复
热议问题