Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - img ng-src to base64 data (not url) not working

I'm using openfb-angular (Facebook API library) to get me/picture.
The return data is "url" contains Base64 data here is the facebook documentation.

Here is my code:

JS

OpenFB.get('/me/picture', {format: 'json'}).success(function (imgData)
        {
            $scope.main.user.imageData = imgData;
        });

HTML

 <img ng-src="data:image/jpg;base64,{{main.user.imageData}}">

It's not working and I get an empty img tag.

Where is my mistake?

like image 428
cheziHoyzer Avatar asked Dec 24 '14 13:12

cheziHoyzer


3 Answers

Use ng-source directive like this:

<img ng-src="{{'data:image/png;base64,'+main.user.imageData}}" >

Hope this helps.

like image 147
Manuel Eguiluz Avatar answered Nov 15 '22 05:11

Manuel Eguiluz


Use data-ng-src directive like this <img data-ng-src="{{data.image_url}}">.

In your controller set base64 string as this: $scope.data.image_url=<your base64 image source>

Hope this helps!

like image 6
Bipin Bhandari Avatar answered Nov 15 '22 04:11

Bipin Bhandari


<img data-ng-src="data:image/png;base64,{{main.user.imageData}}"/>

Hope this helps.

like image 1
Srikanth Avatar answered Nov 15 '22 05:11

Srikanth