I am trying to escape interpolation markers {{
and }}
in the input string to avoid them being executed as interpolation by angularjs 1.8.3
. These markers should be escaped by preceding each of their characters with a REVERSE SOLIDUS U+005C (backslash).
this is what I tried:
var inputString = "{{ code snippet here }}" ;
inputString = inputString.replace("{{", "\\{\\{").replace("}}","\\}\\}");
WHen i set this string back to Html, it gets rendered in output Html as:
\{\{ code snippet here \}\}
I'm expected to show exactly the same as they were in inputString (without \
)
How do I escape these markers without affecting them in output Html?
P.S. I can't use ngNonBindable
which was mentioned in this answer because I can't modify all the Html at this point. And also due to other project-specific reasons.
Code Snippet:
var nodeValue = "{{ 'sample snippet' }}";
nodeValue = nodeValue.replace('{{', '\\{\\{').replace('}}','\\}\\}');
document.getElementById('testtextarea').innerText = nodeValue;
<div ng-app>
<textarea id="testtextarea" cols="50"></textarea>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.3/angular.min.js"></script></div>