4

I'm working on an Angular 2 app in which I had created a dialog which will popup on user click. And the content in that dialog has to be dynamically rendered as html. Static html is running well but dynamic is not running.

Code:

<md-dialog-content><h1>Hello Angular 2</h1></md-dialog-content>////It works..

<md-dialog-content>{{test}}</md-dialog-content>///It does not work.

It displays the text as '<h1>Hello Angular 2</h1>'

In Component:

let test = "<h1>Hello Angular 2</h1>";
1
  • 2
    let = "<h1>Hello Angular 2</h1>"; ?? you have to declare name with let Commented Mar 23, 2017 at 9:51

1 Answer 1

15

You can simply use [innerHTML] directive to achieve it.

<md-dialog-content>
    <span [innerHtml]='test'></span>
</md-dialog-content>
Sign up to request clarification or add additional context in comments.

3 Comments

I want to add an href indise innerHtml. How can I do it?
simply use a instead of span then, is there any issue with this ? and change href with routerLink
@PardeepJain can i use innerHtml with a UI framework like Ant Design ? E.g : test='<nz-table>...</nz-table>'

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.