Reputation: 205
I am trying to display a text file as html. I am using ionic. I am sending a response that is in html format but in a text file to profile page. Its in the variable name in the .ts page.
@Component({
selector: 'page-profile',
templateUrl: 'profile.html',
})
export class ProfilePage{
name: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.name = navParams.get('name');
Now I am trying to display it in in html format using
<div [innerHtml]="name">{{name}}</div>
But I get it in text format and not html. How to display in html format?
Upvotes: 2
Views: 100
Reputation: 2416
You need to use DomSanitizer to bypass html which you provided(bypassSecurityTrustHtml).
constructor(public navCtrl: NavController,
public navParams: NavParams,
private sanitizer: DomSanitizer) {
this.name = sanitizer.bypassSecurityTrustHtml(navParams.get('name'));
}
Read more here: https://angular.io/guide/security#bypass-security-apis
Upvotes: 1