Angular 2 [innerHTML] render inside html (doesn't work on angular 2)

I am using Angular 2 and I am trying to render the text that I have inside the action.render variable as html code:

<p *ngIf="action.isHtml">
      <div [innerHTML]="{{action.content}}"></div>                                               
</p>
<p *ngIf="!action.isHtml">
      {{action.content}}
</p>

      

innerHTML doesn't work in my case. is there any other approach with Angular 2? (this is what I get)

this is my action .content

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
            </title>
            <style type="text/css">
                .cs2654AE3A{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt}
                .csC8F6D76{color:#000000;background-color:transparent;font-family:Calibri;font-size:11pt;font-weight:normal;font-style:normal;}
            </style>
        </head>
        <body>
            <p class="cs2654AE3A"><span class="csC8F6D76">New claim declaration by HD team 00015371</span></p></body>
    </html>

      

enter image description here

+3


source to share


1 answer


Please change your code and try again.

<p *ngIf="action.isHtml">
      <div [innerHTML]="action.content"></div>                                               
</p>
<p *ngIf="!action.isHtml">
      {{action.content}}
</p>

      



You must use either innerHTML="{{action.content}}"

or [innerHTML]="action.content"

but not[innerHTML]="{{action.content}}"

+1


source







All Articles