user824624
user824624

Reputation: 8068

http can not return html content in angular 4

I am working on angular4, trying to load a html template into the page.

this.http.get("/assets/abc.html")
  .subscribe(
    (data) => {
      console.log("--------------"+data);
    }
  );

The result of the http returns me not the html content but only the page path shown as below

--------------Response with status: 200 OK for URL: http://localhost:4200/assets/abc2.html

how to get the real content?

Upvotes: 0

Views: 68

Answers (2)

Andrei Matracaru
Andrei Matracaru

Reputation: 3671

What you get there in the subscription is Response object. To get the actual data, try this:

this.http.get("/assets/abc.html")
  .subscribe(
    (response) => {
      console.log(response.text());
    }
  );

Upvotes: 2

Jeremy Thille
Jeremy Thille

Reputation: 26370

Extract the content of the response with :

this.http.get("/assets/abc.html")
  .subscribe( res => {
      console.log(res.text());
    }
  );

Upvotes: 3

Related Questions