我需要添加一個靜態圖像,如下所示。可以告訴我爲什麼我無法在主頁上顯示圖像,如下所示?即它不工作。在ASP.NET Core + Angular 2上爲Visual Studio設置圖像路徑
這裏我使用這個ASP.NET Core Template Pack
下面是關於它的好文章,從Steven Sanderson
\家\ home.component.html
<img src="{{heroImageUrl}}" style="height:30px">
home.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'home',
template: require('./home.component.html')
})
export class HomeComponent {
public heroImageUrl ="./image/employee_management.jpg";
}
錯誤:
它說,像這樣Failed to load resource: the server responded with a status of 404 (Not Found)
。可能是我issue.how可以給它正確的路徑?圖像如上所示。
那麼先生,這很容易,你可以直接在html中分配你的url src =「」。你不需要角2幫助。但如果你使用變量傳遞圖像認爲它是動態的,我認爲你應該使用絕對路徑。沒有硬的感覺 –
但它不工作不?可能是相對路徑問題否? @AmitSuhag – Sampath
你使用的是webpack?使用絕對路徑。相對路徑將無法工作。您嘗試從./ < - 這意味着您正在從當前目錄進行檢查。從/ app開始我猜不知道你的應用程序結構。爲圖片創建separte文件夾資源 –