1

I am trying to embed a Hosted HTML page in my angular app. However the div is coming back blank. I followed this article and modified the code for angular 7 to no avail Angular4 Load external html page in a div

I console log out the result but it shows empty

My code is a as follows

  template: any = '';
  constructor(http: HttpClient) {
      http.get('http://www.google.com').map((html: any) => this.template = html);
      console.log(this.template);
  }


  <div [innerHtml]="template"></div>

1 Answer 1

1

You need to subscribe to the observable in order to receive the data.

http.get('http://www.google.com').subscribe((html: any) => {
   this.template = html
   console.log(this.template);
});
Sign up to request clarification or add additional context in comments.

8 Comments

I believe that is done automatically when using map. Probably he needs to change his syntax to use pipeable operators.
In order to fire up the observable (including map), we need to use the subscribe method
@enf0rcer I add the content inside the susbcribe function since i don't see why we need map operator in here. But if he is using it then, yes we need to use the pipeable operator
I get an error error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse and message "Http failure during parsing for google.com"
@SachilaRanawaka you are right it makes no sense in this context
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.