6

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.

1
  • isn't it possible to use {{ value }} inside the <span>? Or maybe you can play around with *ngIf and create <span> if some statement is true or otherwise create <p> or whatever you want... Commented Dec 25, 2016 at 0:27

1 Answer 1

6

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.