无法在角度6中获得相对图像路径 [英] Cannot get relative image path in angular 6
本文介绍了无法在角度6中获得相对图像路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的文件夹的结构
angular-src
--src
--app
----components
------whatever.html
public
--images
----01.jpg
我想从whatever.html
访问01.jpg
.
我尝试了许多其他选择,例如<img src="../../../../public/images/01.jpg">
或<img src="../../../../../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.
我使用角度6和节点8.11.1.我在这里想念什么?
I use angular 6 and node 8.11.1. What am I missing here?
谢谢
推荐答案
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屋!
查看全文