Micky
Micky

Reputation: 747

How show an AngularJS variable containing code in HTML <pre> or <code> tag?

Any hint about this? I googled quite a bit but didn't find anything yet..

This code is showing me the variable name instead the code I stored there:

<pre class="prettyprint">{{::data.template}}</pre>

Thanks in advance.

Upvotes: 0

Views: 192

Answers (1)

Lewis Quaife
Lewis Quaife

Reputation: 524

In Angular 1 & 2 you should just be able to use handel bars;

<pre class="prettyprint">{{data.template}}</pre>

You can also bind the data,

Angular 1:

<pre class="prettyprint" ng-bind="data.template"></pre>

Angular 2:

<pre class="prettyprint" [innerText]="data.template"></pre>

You can find more info about binding here - https://www.themarketingtechnologist.co/introduction-to-data-binding-in-angular-2-versus-angular-1/

Upvotes: 2

Related Questions