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(/_/g, " "));
But when I put the same code in my html file like this:
 <th class="text-center" ng-repeat="(key, value) in filteredEL[0] ">
    {{ key.replace(/_/g, ' ') }}
 </th>
it gives following error:
Error: [$parse:syntax] Syntax Error: Token '/' not a primary expression at column 13 of the expression [key.replace(/_/g, ' ')] starting at [/_/g, ' ')]
So, how can I use replace function that replaces all required instances inside the html?
{{ key.replace(/_/g, ' ') }}is considered as angular expression.{{ key.replace('_', ' ') }}works fine but it only removes first instance. I need to replace all of them.key.replace(/_/g, ' ')tries to use aregular expressionto remove all occurences of that pattern. Here is an extract from the Angular docsYou can't declare functions or create regular expressions from within AngularJS expressions. This is to avoid complex model transformation logic inside templates. Such logic is better placed in a controller or in a dedicated filter where it can be tested properly.. Ref: docs.angularjs.org/guide/expression