str.replace not working inside html

前端 未结 2 1521
眼角桃花
眼角桃花 2021-01-20 12:49

I need to replace all _ from a string in my angular app. In my controller, following code gives correct result:

alert(\"this_is_string_\".replace(

2条回答
  •  悲哀的现实
    2021-01-20 13:10

    Using angular filter is the best practice to filter from html.

    Have a look at angular-filter here

    .filter('customFilter', ['$filter', function ($filter) {
        return function (input) {
          if (input) {
          	return input.replace(/_/g, '');
          }
    		}
    }])
    
        {{ key | customFilter}}
     

提交回复
热议问题