I am currently trying to load an image into an img tag. My issue is that the loading of the image cannot be done through a specific src url. so I have created a function which returns the image. I am currently calling the function in the following format with no image been loaded. Please note i have verified that the function does indeed return a value as an array buffer. Thank you for your help!
code:
JS-
//use .factory Img object to return arraybuffer value
$scope.getImage = function(productid) {
console.log(productid);
par = {id: [productid]};
Img.getImage(par).$promise.then(
function(data){
console.log("success:" + data); //I am able to see this result but not display in img tag
return data;
},
function(data){
console.log("error" + data);
}
);
}
HTML-
<img ng-src="{{getimage(id)}}">
getimageis asynchronous, it doesn't return an URL, it's a promise.getimagereturns nothing. The callback of your promise does. You can't synchronously assign an asynchronous value. 1) Get your data. 2) Store it in a variable in your controller. 3) Use this variable as source for your image.