Display images through html img tag with angularjs and ionic

user2429082

I'm currently doing an hybrid mobile app with ionic and Angularjs and i'm trying to display images through an img html tag. My page is composed of a caroussel at the top (which works well, it displays images) and a list with small images. In the controller of my page there is :

app.controller('SalleCtrl', function ($scope,$location) {

$scope.salle = {
    "num": "2",
    "imgR": [
        "img/art_affiche_6_thumb-300x300.jpg",
        "img/art_affiche_6_thumb-300x300.jpg"
    ],
    "title": "Salle 2 : Premières peintures",
    "_audio_guide": [],
    "_audio_guide_fe": [],
    "_audio_guide_en": [],
    "artworks": [
        {
            "img": "img/art_affiche_6_thumb-300x300.jpg",
            "href": "http://172.16.12.158/wordpress/mcm_oeuvre/oeuvre-14-2/",
            "title": "Oeuvre 14"
        },
        {
            "img": "img/art_affiche_9_thumb-300x300.jpg",
            "href": "http://172.16.12.158/wordpress/mcm_oeuvre/oeuvre-3/",
            "title": "Oeuvre 3"
        }
    ]
};
});

And in my html page there is :

<ion-view title="{{salle.title}}">

<ion-nav-buttons side="right">
    <button menu-toggle="right" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>
<ion-content class="has-header" id="" >
    <ul rn-carousel class="image">
         <li ng-repeat="image in salle.imgR" style="background-image:url({{ image }});background-color:black;background-repeat:no-repeat;background-position:center center;background-size : contain;"> 
        </li>
    </ul>

    <div class="list">
        <a ng-repeat="artwork in salle.artworks" class="item item-avatar" href="{{artwork.href}}">
          <img ng-src="{{artwork.img}}">
          <h2>{{artwork.title}}  {{artwork.img}}</h2>   
        </a>
    </div>

</ion-content>

When I display it on a browser everything works well. But when I try on my smartphone the caroussel works, it displays images, but the list doesn't show the images, unstead of {{artwork.img}} show me all the images. I try to :

  1. replace 'ng-src' by 'src' but nothing happens
  2. replace ng-src="{{artwork.img}}" by ng-src="img/art_affiche_6_thumb-300x300.jpg" it works.

Apparently the binding is not correctly made... Have you any idea why? And how resolve it?! Moreover on my smartphone, the path of the images looks like "cdvfile://localhost/persistent/...". The caroussel works well, but the list of image doesn't works, and when I translate "cdvfile://localhost/persistent/..." to "file://mnt/sdcard/..." it works. Why?!

user2429082

I finally find the answer. The problem is due to the fact that angularjs prevent XSS attacks via html link with the function imgSrcSanitizationWhitelist. So the image path which begin with 'cdvfile://localhost/persistent' is prefix by "unsafe:" and so the image is not display. In order to get around this problem I had to override this method, to do that in my config of my main module I add this code :

var app = angular.module( 'myApp', [] )
     .config( ['$compileProvider',function( $compileProvider ){ 
         $compileProvider.imgSrcSanitizationWhitelist(/^\s(https|file|blob|cdvfile):|data:image\//);
       }
     ]);

The discussion with the answer

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Trying to display images using <img> tag in XSLT

From Dev

HTML - how to display local data in img tag?

From Dev

SpringBoot: Why images are not loading html <img src> tag

From Dev

Load images using html <img> tag from Android expansion file

From Dev

How to display images in pairs using AngularJS in html

From Dev

Display images from firebase storage in html img tags

From Dev

How to set inner html through a html tag with angularjs?

From Dev

html tag <img> and <image>

From Dev

How to display linked images horizontally through html or css

From Dev

display a image that starts with a # in <img> tag

From Dev

how to display barcode scan result on html instead of an alert in angularjs + Ionic

From Dev

AngularJS use two way data binding to display image in img element tag as source?

From Dev

JavaFX: in WebView img tag is not loading local images

From Dev

Regex match images but not inside img tag

From Dev

JavaFX: in WebView img tag is not loading local images

From Dev

Faulty img tag not displaying images in Internet Explorer

From Dev

Why is the <img> tag not closed in HTML?

From Dev

HTML img tag not showing the image

From Dev

Get image from JSON file using JavaScript and display in HTML img tag

From Dev

Get image from JSON file using JavaScript and display in HTML img tag

From Dev

What is the difference between using img tag src attribute in HTML to display image and styling it in CSS?

From Dev

Retrieve image from JSON file which is in the database and display in HTML img tag

From Dev

Display images in HTML + Nodejs

From Dev

Display images in HTML + Nodejs

From Dev

display images in admin with HTML

From Dev

SVG does not display in img tag in Safari

From Dev

Display text from img alt tag with beautifulsoup

From Dev

Convert img tag to display FontAwesome icon

From Dev

How to display img tag in conditional statement?

Related Related

  1. 1

    Trying to display images using <img> tag in XSLT

  2. 2

    HTML - how to display local data in img tag?

  3. 3

    SpringBoot: Why images are not loading html <img src> tag

  4. 4

    Load images using html <img> tag from Android expansion file

  5. 5

    How to display images in pairs using AngularJS in html

  6. 6

    Display images from firebase storage in html img tags

  7. 7

    How to set inner html through a html tag with angularjs?

  8. 8

    html tag <img> and <image>

  9. 9

    How to display linked images horizontally through html or css

  10. 10

    display a image that starts with a # in <img> tag

  11. 11

    how to display barcode scan result on html instead of an alert in angularjs + Ionic

  12. 12

    AngularJS use two way data binding to display image in img element tag as source?

  13. 13

    JavaFX: in WebView img tag is not loading local images

  14. 14

    Regex match images but not inside img tag

  15. 15

    JavaFX: in WebView img tag is not loading local images

  16. 16

    Faulty img tag not displaying images in Internet Explorer

  17. 17

    Why is the <img> tag not closed in HTML?

  18. 18

    HTML img tag not showing the image

  19. 19

    Get image from JSON file using JavaScript and display in HTML img tag

  20. 20

    Get image from JSON file using JavaScript and display in HTML img tag

  21. 21

    What is the difference between using img tag src attribute in HTML to display image and styling it in CSS?

  22. 22

    Retrieve image from JSON file which is in the database and display in HTML img tag

  23. 23

    Display images in HTML + Nodejs

  24. 24

    Display images in HTML + Nodejs

  25. 25

    display images in admin with HTML

  26. 26

    SVG does not display in img tag in Safari

  27. 27

    Display text from img alt tag with beautifulsoup

  28. 28

    Convert img tag to display FontAwesome icon

  29. 29

    How to display img tag in conditional statement?

HotTag

Archive