I'm trying to load some images using node's fs module. I have it working on a single image but what is the correct way to do this inside an ngFor loop?
Currently I have:
<div *ngFor="let job of getJobs() | async">
<img src={{readImageFile(job.thumbUrl)}}>
</div>
getJobs() returns an observable from my service.
readImageFile() calls a Meteor server-side method which loads the image data using fs and returns it asynchronously:
readImageFile(url) {
if (url) {
this.call('readImageFile', url, function(err, res) {
if (err) {
console.log(err);
}
else {
console.log('read image file success');
return "data:image/jpg;base64," + res;
}
});
}
}
This doesn't work.. So what is the correct method for asynchronously loading data inside an ngFor loop?
update
I tried with readImageFile(url) | async
readImageFile: function(url) {
var Future = Npm.require('fibers/future');
var myFuture = new Future();
fs.readFile(String(url),
function read(error, result) {
if(error){
myFuture.throw(error);
} else {
myFuture.return(new Buffer(result).toString('base64'));
}
});
return myFuture.wait();
}