【问题标题】:Image sometimes does not show in Angular2图像有时不会在 Angular2 中显示
【发布时间】:2016-03-14 04:16:25
【问题描述】:

我有一张图片<img src="image.png">

当我使用this._router.navigate(['/Home']); 时,有时页面中的图像不会显示。相反,它显示如下:

我试着改成这个:

this._ngZone.run(() => {
    this._router.navigate(['/Home']);
});

但它不起作用。什么可能导致这种情况?谢谢

【问题讨论】:

  • 路径是问题所在。使用基本 href 并根据基本 href 使用路径
  • @Gary 我应该在哪里使用基本 href?谢谢
  • <head><base href="/"></head> 将其用作头部之后的第一行。之后,根据/ 路径(html 文件)的服务器路径使用图像路径。不要使用 HashStrategy
  • 感谢@Gary,它正在工作!

标签: angular angular2-routing


【解决方案1】:
<head>
  <base href="/">
  ...
</head>

将其用作 head 之后的第一行。

之后根据 / 路径(html 文件)的服务器路径使用图像的路径。不要使用 HashStrategy!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多