Html 角度,找不到图像(GET 404)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43994827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:39:43  来源:igfitidea点击:

Angular, image not found (GET 404)

htmlangular

提问by Leonzen

I'm at the moment trying to embed an image to my angular project but I'm getting an error that the immage can not be found.

我目前正在尝试将图像嵌入到我的 angular 项目中,但出现无法找到图像的错误。

GET http://localhost:4200/logo.svg 404 (Not Found)

I have tried to embed the image with the standard method just like this

我试图像这样用标准方法嵌入图像

<img src="../logo.svg">

I have checked the source and also tried other file formats.

我已经检查了来源并尝试了其他文件格式。

回答by Leonzen

@Parth Ghiya commented the answer to my question. I had to put the image to the /src/assets folder. Angular is now able to find the image.

@Parth Ghiya 评论了我的问题的答案。我不得不将图像放到 /src/assets 文件夹中。Angular 现在能够找到图像。

回答by asifaftab87

For me size was the only problem. When I changed size now it is displaying My image path /src/assets/images/products/white.jpg

对我来说,尺寸是唯一的问题。当我现在改变大小时,它显示我的图像路径 /src/assets/images/products/white.jpg

my image url is : /assets/images/products/white.jpg

我的图片网址是:/assets/images/products/white.jpg

回答by Brian Sanchez

ERROR

错误

<img src="src/static/images/logo.png" alt="" width="49" height="35">

SOLUTION(take out the src)

解决方案(取出 src)

<img src="static/images/logo.png" alt="" width="49" height="35">

be happy and "welcome to the scatman's world!"..

快乐并“欢迎来到 scatman 的世界!”...

回答by Raz Zelinger

Let's say you are at your app.component.html if you want to use a picture from your src folder use:

假设您在 app.component.html 中,如果您想使用 src 文件夹中的图片,请使用:

<img src="../../src/logo.svg"> 

Each ../takes you one folder up

每个都../带你一个文件夹

回答by hawran

The solution from Brian worked for me

布赖恩的解决方案对我有用

SOLUTION (take out the src)

<img src="static/images/logo.png" alt="" width="49" height="35">

解决方案(取出 src)

<img src="static/images/logo.png" alt="" width="49" height="35">

回答by murali_cse

First you need to add image in /src/assets/folder. Then type like this.

首先,您需要在/src/assets/文件夹中添加图像。然后像这样打字。

This is works for me!

这对我有用!

htmlfile.html

htmlfile.html

<img src="assets/image/imageName.jpg" >