[英]Why is Image not showing in angular home component project?
我正在處理一個 angular 項目,但試圖將圖像添加到 html 組件中的表行。 圖像未顯示,我嘗試了多種方法使其正常工作,但仍然無法顯示。 這是 home.component.html 代碼:
圖像位於 e2e 文件夾下項目文件夾中名為“images”的文件夾中,位於 node_modules 文件夾之上
<table>
<tr>
<td>
<img src="images/Larissa.jpg" alt="investor1">
<p>"Trusted and quick profit. I use this website many times and I recommend it."</p>
</td>
<td>
<img src="images/petroski.jpg" alt="investor2">
<p>"I feel safe with the knowledge that my investment is secured and safe with Coin Rush."</p>
</td>
<td>
<img src="images/marie.jpg" alt="investor3">
<p>"Thank you i am very impressed”</p></td>
</tr>
</table>
圖像是從那些設置為靜態的文件夾中加載的,或者我們可以說是assets
文件夾。 如果要加載特定資源,則必須將該資源放在 assets 下。
"assets": [
"src/assets"
],
如果要創建新文件夾,請在angular.json
中的angular.json
下提供該文件夾路徑。
並提供從您的文件夾開始的相對路徑。 例如,
Your image is under the path src/assets/images/1.jpg
然后你需要提供路徑作為
<img src="assets/images/1.jpg">
e2e 文件夾不是公用文件夾。 它將被 e2e 測試使用。 您可以通過端到端測試 (E2E) 進行谷歌搜索。 https://coryrylan.com/blog/introduction-to-e2e-testing-with-the-angular-cli-and-protractor
您必須添加一個名為assets
的目錄,在此目錄中您可以存儲項目中所需的所有圖像,要使用這些圖像,您必須在圖像標簽的src
屬性中提供圖像的相對路徑
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.