How to insert image in ionic 2

2019-02-01 08:54发布

I'm new on ionic 2 and i'm trying to insert an image, but i don't realize the real path. inside the file app/pages/getting-started/getting-started.html

<ion-content padding class="getting-started">
  <ion-card>
    <ion-card-content>
      <img src="img1.png" alt="">
      <img src="img/img1.png" alt="">
      <img src="../img/img1.png" alt="">
    </ion-card-content>
  </ion-card>
</ion-content>

Create a folder app/img and inserted an img1.png file inside it. and the same file inside the app/pages/getting-started folder.

So, this should be easy, but can't find anything inside the ionic docs.

Thanks

9条回答
太酷不给撩
2楼-- · 2019-02-01 09:17

I had the same problem while using the Ionic Beta Latest ionic@beta11.


To resolve this problem you can append the images absolute path in the copy.config.js file which will be residing in the node_modules/@ionic/app-scripts/config folder

You can append this file for specific folder by providing source (src) and destination (dest) path.

Hope this helps for copy the images folders to www/build/images folder

Thanks in advance!

查看更多
祖国的老花朵
3楼-- · 2019-02-01 09:25

I had same problem. Only you must create img folder in www. --> www/img (put images in the folder...)

Then in page (html) your must reference <img src="img/logo.png" />

I test in Chrome Browser, App Android and App Ios . (Ionic 2.0.0-beta.11)

Regards!

查看更多
走好不送
4楼-- · 2019-02-01 09:27

Just copy your img folder in the www folder and you're done! ;)

查看更多
登录 后发表回答