0

I'm showing a table of data with "ng-repeat", like so:

<table ng-init="mydata=..." ...>
<tr ng-repeat="item in mydata">
<td>{{item['name']}}</td>
</tr>
</table>

I need to replace something in the content of "item['name']" for display.

I try it like so:

<td>{{item['name'].replace(/aaa/gi,'bbb')}}</td>

This way the display in the TD is empty!

When I do a simple replace, it works fine, for example:

<td>{{item['name'].replace('aaa', 'bbb')}}</td>

Is there a problem with the replace function on AngularJS data when using Regex or am I doing something wrong??

I also need this replace for special characters, like apostrophe (" ' ") and quotes ( " )...

I should mention that in this case, I cannot perform the replace anywhere else AND cannot bring the initial data set other than "ng-init" on the table element.

2
  • 1
    You need to create a filter. An example can be seen [here][1] [1]: stackoverflow.com/questions/12046928/… Commented May 11, 2014 at 7:56
  • As I remember you can't use regex into {{...}}. For beter maintenance, I would use filter as @RArun says or single method: {{replaceMe(item['name'])}} Commented May 11, 2014 at 8:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.