Reputation: 58662
I have an angular expression {{list}}
I don't want angular to execute it - I want to escape it.
I want to print them out as HTML code on my page.
<xmp>
<ul>
<li ng-repeat="list in lists" class="input">
{{list}}
</li>
</ul>
</xmp>
I kept getting
What is the best way do something like that ?
Upvotes: 1
Views: 940
Reputation: 15912
<xmp ng-non-bindable>
<ul>
<li ng-repeat="list in lists" class="input">{{list}}</li>
</ul>
</xmp>
Output
Data
lists = ['one','two','three'];
Angular
<ul>
<li ng-repeat="list in lists" class="input">{{list}}</li>
</ul>
Output
one
two
three
UPDATE
To use HTML syntax...
Here is how StackOverflow does it.
For this piece of HTML
<xmp>
<ul>
<li ng-repeat="list in lists" class="input">{{list}}</li>
</ul>
</xmp>
They use this...
<pre class="default prettyprint prettyprinted">
<code>
<span class="tag"><xmp</span>
<span class="pln"> </span>
<span class="atn">ng-non-bindable</span>
<span class="tag">></span><span class="pln"> </span>
<span class="tag"><ul></span><span class="pln"> </span>
<span class="tag"><li</span>
<span class="pln"> </span>
<span class="atn">ng-repeat</span>
<span class="pun">=</span>
<span class="atv">"list in lists"</span><span class="pln"> </span>
<span class="atn">class</span><span class="pun">=</span>
<span class="atv">"input"</span>
<span class="tag">></span>
<span class="pln">{{list}}</span>
<span class="tag"></li></span>
<span class="pln"> </span>
<span class="tag"></ul></span>
<span class="pln"> </span>
<span class="tag"></xmp></span>
</code>
</pre>
Do something similar but with your own styling. It looks like you will be having static HTML for a lesson of some sorts, but you could just make the rendered text in a string format that gets rendered dynamically with the correct classes using ngClass.
Upvotes: 1
Reputation: 6276
You may escape angular curly braces with multiple ways, using HTML comments, ng-non-bindable
tag or even a interrupting HTML element
<div ng-app="" ng-init="lists = ['one','two','three'];">
echo: {{lists}}</br>
escape 1: <code ng-non-bindable>{{lists}}</code></br>
escape 2:{{lists}<!-- -->}</br>
escape 3:{{lists}<span/>}</br>
</div>
Keep in mind that you may easily change curly to braces to whatever you want:
var app = angular.module('app')
.config(['$interpolateProvider', function ($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
}]);
Upvotes: 1
Reputation: 8598
Use 'ng-non-bindable' in the element.
Example:
<div ng-non-bindable>This is a {{profile}}</div>
Will simply show:
This is a {{profile}}
Upvotes: 5