Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: Expression containing markup

I'm looking for a way to tell Angular to display a value inside an expression that contains markup, and actually use the HTML:

{{ value }}

let value = "<span>foobar</span>";

So, the value variable contains a string with markup, and I want to apply the markup so it is rendered in the page. So if value contained <b>test</b>, then on the page, bold text would appear.

like image 834
mtyson Avatar asked Dec 25 '16 00:12

mtyson


1 Answers

Guess you are looking for innerHTML:

value: string = "<span>foobar</span>";

<div [innerHTML]="value">
</div>

The code above will be rendered to:

<div>
    <span>foobar</span>
</div>
like image 95
Stefan Svrkota Avatar answered Sep 27 '22 20:09

Stefan Svrkota