I wanted to do a quick test and see if <span ng-bind="test.id"></span>
would be better than using {{test.id}}
for data-binding. Would there by a way I could do this in regex for the whole app?
I'd have to make sure that it doesn't replace variables that are inside of a tag like <div id="chat-{{otherPerson.id}}" ...>
, so it would only be replacing things like <div class="message">{{message.body}}</div>
.
I'd also need to be able to check if there was a filter being used: {{ otherPerson | fullname}}
{{ otherPerson | fullname}}
Is this even possible with regex, or would I need to write a grunt task to take care of it?
I believe you should be able to use this type of regex
/([^'"])\{\{([^\}|]+)\}\}/gi
and replace with
'$1<span ng-bind="$2"></span>'
Hope it helps!
I think you can use this regex:
/(^|(>[^\<]*)|(^[^\<]*))(\{\{[^\{\}]*\}\})/igm
and use its substitution $4
.
If I got you correctly, you want to replace
>\s*\{\{([^|}<]+)\}\}
with
ng-bind="\1">
Note that the replacement has space in front.
For the filter case you can replace
>\s*\{\{([^|}<]+\|[^|}<]+)\}\}
with
ng-bind="(\1)">
You could try multiple pass approach
"(.*)\\{\\{([^\\|]+?)\\}\\}(.*)"
replace with "$1[[[$2]]]$3"
\\{\\{\\s*([^\\|]+?)\\s*\\}\\}
replace it with <span data-bind="$1"></span>
\\[\\[\\[
replace with {{
\\]\\]\\]
replace with }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.