4

i am using Angular 2 and i try to render the text which i have inside the variable action.render as html code:

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

the innerHTML doesn't work in my case. is there any other approach with Angular 2? (here 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

kostas
  • 779
  • 4
  • 13
  • 20

1 Answers1

3

Change your code to this and try again :

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

You should use either innerHTML="{{action.content}}" or [innerHTML]="action.content" but not [innerHTML]="{{action.content}}"

Vivek Doshi
  • 56,649
  • 12
  • 110
  • 122