For some reason my listImage()
method returns a null I don't know what I could be doing wrong. for some reason my listImage()
method returns null
.
import {
Injectable,
}
from '@angular/core'
declare
var firebase;
@
Injectable()
export class StorageService {
img:any;
listImage() {
var getImages = firebase.database().ref('flats').once('value');
getImages.then(snapshot => {
var imgName = snapshot.val();
var names;
snapshot.forEach(imgName => {
names = imgName.val();
let i = names.image;
//console.log(i);
let key = imgName.key
firebase.storage().ref(i + '.jpg').getDownloadURL().then(url => {
this.img = url;
});
})
})
return this.img;
}
}
could it be the forEach()
restricting it
constructor(public navCtrl: NavController, service: StorageService) {
this.service = service;
var img = this.service.listImage();
console.log(img); //this returns null what could be the issue?
}