0

I want to display images from sdcard in my Ionic application , But I got problem to show images with img tag.

View Code For My Application

<ion-content ng-controller="DigitalCatCtrl">
<div>
       <img ng-src="{{myimg}}" />
       <img src="{{myimgs}}" />
</div>
</ion-content>

Controller Code For My Application

.controller('DigitalCatCtrl', function($scope,$cordovaFile) {
      $scope.myimg=cordova.file.externalRootDirectory + ".DigitalCatlog/ic_developmentworks.png";
      $scope.myimgs="file:///storage/sdcard0/.DigitalCatlog/ic_developmentworks.png";
    });

If I have pass the image path directly to img tag like following way, Image will show.

<img src="file:///storage/sdcard0/.DigitalCatlog/ic_developmentworks.png" />

Please suggest me what I did wrong or any other solution.

Santosh Shinde
  • 6,045
  • 7
  • 44
  • 68

1 Answers1

4

use

<img data-ng-src="{{myimgs}}" />

instead

<img src="{{myimgs}}" />
Vineet
  • 4,525
  • 3
  • 23
  • 42
  • @Vineet cordova.file.externalRootDirectory showing error: Cannot read property 'externalRootDirectory' of undefined – Rahul Sharma Sep 07 '16 at 09:25
  • @RahulSharma Unfortunately I don't have much experience with `corodova` but as per seen above, I guess your plugin is not reading the file properly or may be it's a permission issue ( I've just google it ). I hope this article will help you http://stackoverflow.com/questions/38226470/android-app-cant-read-external-storage-files/38226786#38226786 – Vineet Sep 07 '16 at 10:33
  • @Vineet: i just solve that issue.. but now its showing `Not allowed to load local resource` can you please help me about it? – Rahul Sharma Sep 07 '16 at 10:37