Loading image src using a variable containing base64 data in AngularJS

一世执手 提交于 2019-11-26 16:59:50

问题


Loading image using variable containing base64 data in AngularJS

I am trying to find the right way to load a image source from a variable containing base64 encoded image data (for example pulled from a canvas using toDataURL(); ).

At first I just tried it like this:

<img src="{{image.dataURL}}" />

where the image is a scope variable with a variable dataURL containing the base64 data. This is actually working pretty well, the only problem is that I get a 404 error in my console. Something like this:

GET http://www.example.com/%7B%7Bimage.dataURL%7D%7D 404 (Not Found)

Not so pretty. When I tried a more angular style solution like this:

<img data-ng-src="image.dataURL" />

the images are not loading at all. I made a fiddle which you can find HERE

Any suggestions how to get rid of this error in my console?


EDIT:

Gruff Bunny was right. This <img data-ng-src="{{image.dataURL}}" /> is working...

Working solution can be found HERE


回答1:


The content of the ng-src needs to be interpolated: Try this:

<img data-ng-src="{{image.dataURL}}"/>



回答2:


I admit I spent way too much time trying to fix similar problem,

my problem was I had extra brace here (see three braces at end):

 ng-attr-src="{{aad.form.imageBase64Temp}}}"


来源:https://stackoverflow.com/questions/22018776/loading-image-src-using-a-variable-containing-base64-data-in-angularjs

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