Ionic DomSanitizer gives Uncaught TypeError: Cannot read property 'offsetHeight' of null


#1

As many other people I’m trying to retrieve an HTML page from a server to display it on a IONIC app.

Here’s the template/html:

<ion-content padding [innerHtml]="HTMLcontent">
</ion-content>

And here’s the module:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Http } from '@angular/http';
import { DomSanitizer } from "@angular/platform-browser";

export class RandomPage {
  HTMLcontent;
  constructor(public navCtrl: NavController, public navParams: NavParams, private http:Http, private sanitizer: DomSanitizer) {}
  ionViewDidLoad() {
    this.http.get("SAFE_URL_HERE").subscribe(html=>{
      this.HTMLcontent = this.sanitizer.bypassSecurityTrustHtml(html['_body']);
    });
  }
}

Now, the problem is that whenever I try to access this page I get this error:

Uncaught TypeError: Cannot read property 'offsetHeight' of null
    at Content.getContentDimensions (content.js:529)
    at Content._readDimensions (content.js:693)
    at content.js:220
    at SafeSubscriber.schedulerFn [as _next] (core.js:4235)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:238)
    at SafeSubscriber.next (Subscriber.js:185)
    at Subscriber._next (Subscriber.js:125)
    at Subscriber.next (Subscriber.js:89)
    at EventEmitter.Subject.next (Subject.js:55)
    at EventEmitter.emit (core.js:4203)

The only workaround I found for now is to have a template like this:

<ion-content padding>{{HTMLcontent}}</ion-content>

But it will output text instead of HTML, so it’s not OK