2

I'm trying to render an html string so that it displays links, etc using Ionic. This is my very first Ionic app.

<ion-content class="home">
<ion-list>
  <ion-item *ngFor="let f of item">
    <h2 class="question" style="white-space:initial;" ng-bind-html="{{f.question}}">{{f.question}}</h2>
    <p class="answer" style="white-space:initial;" ng-bind-html="{{f.answer}}">{{f.answer}}</p>
  </ion-item>
</ion-list>
</ion-content>

I've tried ng-bind-html as above and it's saying...

Unhandled Promise rejection: Template parse errors: Can't bind to 'ng-bind-html' since it isn't a known property of 'h2'. ("

I've also tried ng-bind-html-safe but that produces the same error. Without the ng-bind-html code, the string is displayed but with the html characters not being interpreted.

Also, here is the code coming from the .ts file

  this.faqService.load()
  .then(data1 => { 
    this.item = data1;
  });
Cary
  • 278
  • 1
  • 3
  • 17

1 Answers1

4

The answer to my question is

<p [innerHTML]="f.answer"></p> 

Hope this helps other newbies to Angular 2 / Ionic.

Cary
  • 278
  • 1
  • 3
  • 17
  • This allows for cross site scripting You should use it very sparingly. –  Mar 07 '17 at 12:49