Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

angular - Ionic 2 Images not displaying on device

It just seems the simplest of things such as using the correct url path for an image can consume so much time and effort with no success at all.

So, in my homepage I tried to use one of the following:

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

All of which display on the browser and but not on the device.

I've read so many threads and it is disgraceful that yet there is no real solution to this. I would really like to know what it is I am doing wrong here? Any helps and real solutions would be very much appreciated.

question from:https://stackoverflow.com/questions/42830752/ionic-2-images-not-displaying-on-device

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same issue with relative paths

<img src="../assets/img/vis_reco.png">  

does work with ionic serve / and also with livereload in the emulator (e.g. from src/pages/home/home.html ) But not on the device.

Don't use relative paths for images !!!

<img src="assets/img/vis_reco.png">  

works for me with Ionic (v3) and also angular typescript apps. On the device (ionic cordova run) with ionic serve and also with ng s (angular apps)

used dir tree:

used dir tree

you can see an (official) example in the ionic conference starter, try:

ionic start ionicConf conference

(btw: same quetiosn & answer here: https://forum.ionicframework.com/t/images-not-displayed-on-device/89145 )


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...