为什么图像没有显示在有角度的家庭组件项目中?



我正在处理一个角度项目,但试图将图像添加到 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": [
"src/assets"
],

如果要创建新文件夹,请在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属性中提供图像的相对路径

最新更新