无法获得角度为 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">