简体   繁体   English

角度:无法加载图像:404(未找到)

[英]Angular : Failed to load images: 404 (Not Found)

i download this free theme in order to use it in my angular project in WebStorm but i get this error :我下载了这个免费主题,以便在 WebStorm 的 angular 项目中使用它,但出现此错误:
Failed to load resource: the server responded with a status of 404 (Not Found) and no image is loaded even if the path is right. Failed to load resource: the server responded with a status of 404 (Not Found)并且即使路径正确也没有加载图像。 can anyone help me with that?任何人都可以帮助我吗?

here is a snippet of the code:这是代码的一个片段:

 <a class="navbar-brand brand-logo" href="index.html"><img src="images/logo.svg" alt="logo"/></a>
      <a class="navbar-brand brand-logo-mini" href="index.html"><img src="images/logo-mini.svg" alt="logo"/></a>

What i get我得到了什么

Directory tree structure目录树结构

PS: i did have problems with loading CSS and JavaScript files but i'v already solved them by adding type="text/html" in css links and type="application/json" in JavaScript links. PS:我确实在加载 CSS 和 JavaScript 文件时遇到了问题,但我已经通过在 css 链接中添加 type="text/html" 和在 JavaScript 链接中添加 type="application/json" 来解决这些问题。 do you think it can be a JSON problem?你认为这可能是一个 JSON 问题吗?

I solved this issue by placing images into assets folder of Angular.我通过将图像放入 Angular 的assets文件夹解决了这个问题。 Previously I placed them into app folder and had 404 error too, but placing into assets solved my issue.以前我将它们放入app文件夹中,也有 404 错误,但放入assets解决了我的问题。 So I use them like:所以我使用它们:

 <img src="assets/images/intro_room.jpg" alt="Intro Gallery Room Sample Pictures">

尝试使用/ like /images/logo.svg开始您的图像源链接

当文件夹即图像和index.html文件在同一目录中时,路径应以./

<img src="./images/logo-mini.svg" alt="logo"/>

You have to add the route in angular.json in architect > build > options > assets:您必须在 angular.json 中的 Architect > build > options > assets 中添加路由:

"assets": ["src/favicon.ico", "src/assets", "src/images"]

After this you have to stop it and relaunch you app.在此之后,您必须停止它并重新启动您的应用程序。

我不知道您在资产目录中真正拥有什么,但尝试将所有静态文件(如 css 和图像)放入资产目录中。

The answer here: You have to add the route in angular.json in architect > build > options > assets:答案在这里:您必须在 angular.json 中的 Architect > build > options > assets 中添加路由:

"assets": ["src/favicon.ico", "src/assets", "src/images"] "assets": ["src/favicon.ico", "src/assets", "src/images"]

After this you have to stop it and relaunch you app.在此之后,您必须停止它并重新启动您的应用程序。

from Ivan Gomez is likely the true right answer.来自 Ivan Gomez 可能是正确的答案。 This worked 100% for me.这对我来说是 100% 的。 The real reason the image directory did not work was that angular did not have it registered as an asset driectory.图像目录不起作用的真正原因是 angular 没有将其注册为资产目录。 Adding the image to the asset folder is also correct, but if you want your own image folder to hold images you need to add it to the angular.json file as Ivan directs.将图像添加到资产文件夹也是正确的,但是如果您希望自己的图像文件夹保存图像,则需要按照 Ivan 的指示将其添加到 angular.json 文件中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载图像,服务器响应未找到404 - Failed to load images, server responds with 404 not found 无法加载资源:服务器响应状态为404(未找到)角度js +离子 - Failed to load resource: the server responded with a status of 404 (Not Found) angular js + ionic Angular 6正在加载图像错误。 收到“无法加载资源:服务器以404(未找到)状态进行响应” - Angular 6 Getting Loading image error. Getting a “Failed to load resource: the server responded with a status of 404 (Not Found)” 加载资源失败:服务器响应状态为 404(未找到)css - Failed to load resource: the server responded with a status of 404 (Not Found) css 加载资源失败:服务器响应状态 404(未找到) - Failed to load resource: the server responded with a status 404(not found) 加载资源失败:服务器响应状态为 404(未找到) - Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为 404(未找到) - Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为 404(未找到)GoogleBooks Api - Failed to load resource: the server responded with a status of 404 (Not Found) GoogleBooks Api 加载资源失败:服务器响应状态为 404 (Not Found) --&gt; favicon not loading - Failed to load resource: the server responded with a status of 404 (Not Found) --> favicon not loading 无法加载资源:服务器响应状态为 404(未找到),显示在控制台上 - Failed to load resource: the server responded with a status of 404 (Not Found) displayed on console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM