Mohan Gopi Mohan Gopi - 6 months ago 19
AngularJS Question

How to store an image url received from server to variable in angular js and ionic

I am trying to get my image url from response object and store it in a variable here is my code for getting the image url from server

$http.post("http://aflaree.com/apmsservice/securityService.svc/AvailableFacility",loginID)
.success(function(response){
console.log(response);
console.log(response.facility);
console.log(response.FacilityImage);
$scope.img = response.FacilityImage;
console.log($scope.img);
})
.error(function(response){
console.log(response);
});


Here is my response for the above post method.

Here is my html where i am planing to display image

<div >
<img ng-src="{{img}}">
</div>


Issues

I am able to store or view my log for any field from response except FacilityImage field.

some how if i am able to store the image into $scope.img then using two way data binding will be able to show my image in html page

if there is any other way to make access of that image url form FacilityImage please let me know how to show that image to my view.

Answer

FacilityImage is an attribute of facility, therefore you have to access it like this:

response.facility.FacilityImage

Hope this helps!

UPDATE: actually event a level deeper, as facility is an array with multiple facilities, so assuming you pick the first one:

response.facility[0].FacilityImage