2017-08-12 50 views
0

我在后端使用表达式的节点js,我有一个静态文件夹,其中包含一些图像,所以我试图加载这些角度为2的图像在客户端,这是我的代码的一部分:Angular 2:从静态存储使用快速js获取图像

后端侧:

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本地主机:3000 /图像/ image1.png 404(未找到) -

+0

什么不起作用?你没有看到图像? – alexmac

+0

@alexmac这是错误:image1.png:1 GET http:// localhost:3000/Images/image1.png 404(Not Found) – nadhem

+0

不确定,但'区分大小写'在这里很重要,会建议您更改'images'到'/ images' –

回答

0

我加载我的图片的方法是象下面这样:

<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'))); 

,并可能是你可能需要修改你的:

enter image description here

+0

你尝试删除“http:// localhost:3000”吗? –