Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将外部HTML加载到Angular 2组件时,相对引用会中断_Html_Angular_Typescript - Fatal编程技术网

将外部HTML加载到Angular 2组件时,相对引用会中断

将外部HTML加载到Angular 2组件时,相对引用会中断,html,angular,typescript,Html,Angular,Typescript,我有一个托管简单HTML的服务器,如下所示: <a href="http://www.google.com" target="_blank"> <img src="img/main.PNG"/> </a> 如果我更改服务器上的HTML以返回图像的绝对URL,则它可以工作: <img src="http://localhost:5500/img/main.PNG"/> 然而,就我而言,这不是一个可行的解决办法 所以我的问题是: 有没有

我有一个托管简单HTML的服务器,如下所示:

<a href="http://www.google.com" target="_blank">
   <img src="img/main.PNG"/>
</a>
如果我更改服务器上的HTML以返回图像的绝对URL,则它可以工作:

 <img src="http://localhost:5500/img/main.PNG"/>

然而,就我而言,这不是一个可行的解决办法

所以我的问题是:
有没有一种方法可以通过Angular 2从外部源加载HTML内容,并且不会破坏所述HTML中的相对引用?

尝试将
“img/main.PNG”
更改为
“/img/main.PNG”

您尝试过“/img/main.PNG”吗。。。这很尴尬。这很有效,谢谢!:)
this.myService.subscribe(
  (html: any) => {
     this.content = html._body;
     this.loaded = true;
  },
  err => {
    this.error = true;
  });
 <img src="http://localhost:5500/img/main.PNG"/>