[英]Angular2: Load content of html page into a variable
So I have an html page located in this path: 因此,我在此路径中有一个html页面:
./Help/HelpMenu/How-To-Bake-Pies.html ./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: 我正在尝试将此HTML页面的内容加载到string类型的变量中,如下所示:
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? 执行第二条语句后, _content变量保持为空,我是否缺少某些内容?
You need to subscribe
to the observable otherwise it won't get executed - in other words, the HTTP call will never happen 您需要subscribe
可观察的对象,否则它将不会被执行-换句话说,HTTP调用将永远不会发生
this.http
.get("./Help/HelpMenu/How-To-Bake-Pies.html")
.subscribe((html:any) => this._content = html);
map
does not subscribe to the observable. map
未订阅可观察的map
。 It is used to manipulate data. 它用于处理数据。 map
returns a new observable that you can subscribe to. map
返回您可以订阅的新可观察对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.