无法获得角度为 6 的相对图像路径 [英] Cannot get relative image path in angular 6

查看:21
本文介绍了无法获得角度为 6 的相对图像路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的文件夹结构

angular-src
--src
--app
----components
------whatever.html
public
--images
----01.jpg

我想从 whatever.html 访问 01.jpg.

我尝试了很多替代方法,例如 <img src="../../../../public/images/01.jpg"><imgsrc="../../../../../public/images/01.jpg"> 并且我不断收到 404.

I tried many alternatives like <img src="../../../../public/images/01.jpg"> or <img src="../../../../../public/images/01.jpg"> and I keep getting 404.

我使用 angular 6 和节点 8.11.1.我在这里缺少什么?

I use angular 6 and node 8.11.1. What am I missing here?

谢谢

推荐答案

在您的 .angular.json 中,您可以将 glob 定义为 一个

In your .angular.json you can define the glob as this one

"assets": [
    {"glob": "**/*", "input": "../../public", "output": "./assets/"}
]

这会将您的 public 文件夹的内容复制到 /dist/assets/ 目录.然后,像

This will copy the contents of your public folder to the /dist/assets/ directory. Then, use it like

<img src="assets/images/01.jpg">

这篇关于无法获得角度为 6 的相对图像路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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