sercan sercan - 9 months ago 32
AngularJS Question

How to put prefix on expressions surrounded by curly brackets

What could be the javascript regex expression of putting prefix to all values in angular curly braclets ?

//prefix : listItem
<span>{{name}} {{surname}}</span>
<span>{{}} {{listItem.surname}}</span>


You can use String.prototype.replace() with RegExp /(\w+)(?=\}\})/g to match word followed by }}

var span = document.querySelector("span");
span.textContent = span.textContent.replace(/(\w+)(?=\}\})/g, function(match) {
  return "listItem." + match
<span>{{name}} {{surname}}</span>