6

I am trying to add a variable containing html to my ionic 3 page

Ionic Page:

<ion-header>

  <ion-navbar>
    <ion-title>{{offeritem.data.nameprovider}}</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
  <div>
    {{offeritem.data.detailsoffer}}
  </div>
</ion-content>

However I am getting the following

Result:

<p>The table contains 30 pieces:</p><ul><li>5 Philadelphia Roll</li>
<li>5 Fantasia Roll</li>

Please let me know what I am doing wrong in this case.

Thanks in advance

5
  • what is expected output? Commented May 22, 2017 at 10:29
  • if you use {{}}, it will consider that as string only Commented May 22, 2017 at 10:30
  • If I use the variable without {{}} I just get the offeritem.data.detailsoffer as a string. The expected result is a formatted html content based on the variable value. Currently I only get the html string value. Commented May 22, 2017 at 11:11
  • ng-bind-html use this attribute...w3schools.com/angular/ng_ng-bind-html.asp..if incase of ionic2+ use [innerhtml] or other alternative Commented May 22, 2017 at 11:21
  • Thanks for your comments however after trying both options none of them worked. Maybe I am doing something wrong. Do you believe there is any Ionic framework or Ionic way dependency on this? Commented May 22, 2017 at 12:42

3 Answers 3

14

You should use [innerHTML] for ionic 3 like this:

<p [innerHTML]="yourVarHere"></p>
Sign up to request clarification or add additional context in comments.

Comments

5
<span [innerHTML]="offeritem.data.detailsoffer"></span>

REF

Note the section on "Property binding or interpolation?"

2 Comments

Thanks for your last answer, this allowed to me to address my search and found this <p [innerHTML]="offeritem.data.detailsoffer"></p> it works perfect now
@JADSAM can you change the correct answer then? This one is not correct.
3

import {DomSanitizationService} from '@angular/platform-browser';

class....{
  public getSafehtml(html:string){
    return this.sanitizer.bypassSecurityTrustHtml(html);
  }
}
<ion-content padding>
  <div [innerHTML]="getSafehtml(offeritem.data.detailsoffer)"></div>
</ion-content>

If you not bypassSecurityTrustHtml then your style will not work.

1 Comment

I'm used DomSanitizer.

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.