何らかの理由で私のlistImage()
メソッドがnullを返します。何が間違っているのか分かりません。何らかの理由で私のlistImage()
メソッドはnull
を返します。 メソッドは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;
}
}
はそれはそれは
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?
}
これは非同期メソッドです。この問題に関する多くの質問があります。私はそれが角度2の問題ではないことを物事 – yurzui
ああ私はそこに回避策があります角法やライブラリがない参照してください。 –