I have api which return image corresponsding to the userID.
API code whcih return image:
public function getImage($id) {
if(File::exists('uploads/'.$id.'.jpg')) {
$image = File::get('uploads/'.$id.'.jpg');
return Response::make($image, 200, array('content-type' => 'image/jpg'));
} else {
return Response::json(array('error'=>true,'details'=>'No image.'));
}
}
Route to get image is "api/image/id"
AngularJS Code:
QAApp.controller('imgCtrl', function ($scope, $http) {
$scope.image = function (id) {
$http({
method: 'GET',
url: server + 'api/image/' + id,
}).success(function(data){
console.log(data);
$scope.imageUrl= data; // if you sure what data is you URL
})
}
});
HTML Code :
<div class="artst-pic pull-left" ng-controller="imgCtrl">
<img ng-src="{{imageUrl}}" ng-init="image(q.userID)" alt="" class="img-responsive" />
</div>
If I give the api path with server path then I get the image but if I am using that api path in angularsjs code, I didnt get image, I an getting the response like that:
�ޑ�����b���[����T��Ԏ�����{����O���Q(�b'��ձ�3]Ӵ������ۯ��I��U+��=>���i�C�~o�����/2fh�*������]Y�]�ƅ���ԋ��ʋj�ў��
I dont know why this is happen, please tell me if anybody know about this.
ng-srcrather than getting back the actual image.<img ng-src="/folder-having-images/image.jpg". so what you need in ng-src is the path of the file and not the image. e.g.ng-src="/uploads/7.jpg"you dont need the $http call.