【问题标题】:Angular 2 : get image from a static storage using express jsAngular 2:使用 express js 从静态存储中获取图像
【发布时间】:2017-08-13 06:43:57
【问题描述】:

我在后端使用带有 express 的 node js,我有一个包含一些图像的静态文件夹,所以我试图在客户端加载具有 angular 2 的图像,这是我的代码的一部分:

后端:

app.use(express.static(__dirname + '/Images')); //'./Images' contains images that I need 

前端:

<mg src="http://localhost:3000/Images/image1.png" /> //it's a fruitlessly try 

这是显示的错误:

image1.png:1 GET localhost:3000/Images/image1.png 404(未找到)-

【问题讨论】:

  • 什么不起作用?你没看到图片?
  • @alexmac 这是错误:image1.png:1 GET localhost:3000/Images/image1.png 404(未找到)
  • 不确定,但case sensitivity 在这里是否重要,建议您将images 更改为/images

标签: node.js angular express


【解决方案1】:

我加载图片的方式如下:

   <div class="chromecast">
      <img class="img-responsive" 
        src="/images/chromecast-site.jpeg" [style.width]="imageWidth" 
        height="auto">
   </div>

我忽略

"http://localhost:3000

我的 server.ts 在下面

// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
app.use(express.static(path.join(__dirname, 'public')));

你可能需要修改你的:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-15
    • 2017-12-23
    • 1970-01-01
    • 2018-03-21
    • 2013-05-06
    • 2016-01-16
    • 2018-03-14
    • 2015-10-27
    相关资源
    最近更新 更多