Luca Trembon Luca Trembon - 1 year ago 225
HTML Question

Ionic 2 - Local image wont display

im pretty new to Ionic 2. I switched from Ionic 1 because it feels to be the better choice. To me it seems like a lot of structural and syntax changes have been made.

Currently im trying to use a local picture in one page. Thatswhy i tried to use this code.

<img src="../../../www/img/icon.jpeg">

Unfortunately it doesn´t work. Thatswhy i began to google it, they recommended to make some changes in the gulpfile js. Does this still exist? It seems like they also changed alot between the beta- and the release version.

Thanks alot in advance.


Answer Source

If you use the current version of Ionic (RC1) including all the surroundings like app-scripts you are supposed to put your images to src/assets. During the build process ('ionic serve' or 'ionic build [PLATFORM]') this will be copied over to www/assets. In order to link them properly in your templates you have to link them like this:

<img src="assets/icon.jpeg">

I personally created an img folder within the assets folder to separate it from other content. Obviously in that case you have to adjust the link to something like

<img src="assets/img/icon.jpeg">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download