Angular 6无法从资产加载图像 [英] Angular 6 Failing To Load Images From Assets

查看:132
本文介绍了Angular 6无法从资产加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我无法在我的应用中显示图片. 这是错误,测试和类:

For some reason I can't get my images to show in my app. This is the error, tests and class:

The error: GET http://localhost:4200/assets/image.png 404 (Not Found)

<img class="logo" src="../../assets/image.png">
<img class="logo" src="../assets/image.png">
<img class="logo" src="assets/image.png">
//None of these work

.logo {
    height: 100px;
    width: auto;
    padding: 10px;
    display: block;
    margin: 0 auto;
}

有人知道为什么这行不通吗?我的image.png位于我的资源文件夹中,该文件夹位于src/assets/image.png.

Any idea why this is not working? My image.png is in my assets folder which is located at src/assets/image.png.

更新:

所以我们做了一个测试.我们将所有节点模块和项目文件复制到另一台PC,并且图像已正确加载.因此,我认为问题出在它本身的角度投影之外.

So we did a test. We copied all the node modules and the project files to another pc and there the images loaded correctly. So I assume the problem lies outside the angular project it self.

推荐答案

<img class="logo" src="assets/image.png">

这是正确的道路,可能其他地方出了错.

This is the right path, probably something else went wrong.

检查图像名称或它的jpeg. 也许您在资产文件夹中添加了一个新文件夹? ,如图片,则代码应如下所示

check that the image name or if its jpeg. maybe you added a new folder in the assets folder ? , like images if so the code should look like this

<img class="logo" src="assets/image/image.png">

这篇关于Angular 6无法从资产加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆