I am facing an issue where I need to return the URL of each ID I receive, but the URL is being generated asynchronously. This delay in generation is causing a problem as I am unable to display it on the view immediately. How can I make the code wait until the data is fetched from PouchDB and the URL is generated?
controller
$scope.getColour = function(id) {
var texture_array = [];
texture_array = photoList.data.economy.concat(photoList.data.luxury, photoList.data.premium);
var db = PouchDB('new_test4');
var obj = {};
var array = [];
var i;
for (i = 0; i < texture_array.length; i++) {
if (texture_array[i].image_url == id) {
db.getAttachment(id, id, function(err, blob_buffer) {
if (err) {
return console.log(err);
} else {
var url = URL.createObjectURL(blob_buffer);
console.log(url);
return url;
}
});
}
}
};
html
<div class="item" ng-repeat="photoOuterObj in remainingEconomyColour " ng-class=" $index? '' : 'active'">
<div class="row" ng-repeat="photoInnerObj in photoOuterObj">
<div class="premium-carousel-image">
<a class="color-image"> <img src="{{getColour(photoInnerObj.image_url)}}" alt="Image" /></a>
<div class="ambience-button">
</div>
</div>
</div>
</div>