Eric Bergman
Eric Bergman

Reputation: 1443

Angular2: Load content of html page into a variable

So I have an html page located in this path:

./Help/HelpMenu/How-To-Bake-Pies.html

I'm trying to load the contents of this html page into a variable of type string like so:

private _content: string = '';

this.http.get("./Help/HelpMenu/How-To-Bake-Pies.html").map((html:any) => this._content = html);

After the second statement is executed the _content variable remains empty, am I missing something?

Upvotes: 0

Views: 417

Answers (1)

Sonu Kapoor
Sonu Kapoor

Reputation: 1637

You need to subscribe to the observable otherwise it won't get executed - in other words, the HTTP call will never happen

this.http
.get("./Help/HelpMenu/How-To-Bake-Pies.html")
.subscribe((html:any) => this._content = html);

map does not subscribe to the observable. It is used to manipulate data. map returns a new observable that you can subscribe to.

Upvotes: 2

Related Questions