How to display a local:// image in ionic framework + cordova?

情到浓时终转凉″ 提交于 2019-12-14 00:53:24

问题


Does anyone know how to display local images, packaged inside a Cordova container, using Ionic (http://ionicframework.com/docs/)?

I am currently getting this error when the app runs on a device:

GET unsafe:local:///img/thumbs/myImage.jpg Unhandled Protocol

My Cordova app is built for BlackBerry 10 & Android using ionic framework. The app displays an image that is packaged inside the Cordova app itselfusing the following template:

<img ng-src="img/thumbs/{{img.path}}" ng-click="fooBar(img)"/>

Why is this error occurring?


回答1:


I've discovered this is a current limitation of the ionic framework regarding BlackBerry 10 support. I've logged a bug here: http://github.com/driftyco/ionic/issues/1066

To fix this, I've since manually edited the ionic library to include support for the local protocol.




回答2:


I've just pull request to Angular, because it's an Angular limitation, not of the Ionic framework. You can see the pull-request here: https://github.com/angular/angular.js/pull/8787




回答3:


Angular issue

Replace following lines in ionic.bundle.js

var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
     imgSrcSanitizationWhitelist = /^\s*((https?|ftp|file|blob):|data:image\/)/;

to

var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file|local):/,
     imgSrcSanitizationWhitelist = /^\s*((https?|ftp|file|blob|local):|data:image\/)/;


来源:https://stackoverflow.com/questions/22886437/how-to-display-a-local-image-in-ionic-framework-cordova

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!