2017-08-12 52 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」嗎? –