我的离子项目有问题 . 我所做的是将firebase数据库中的数据提取到fooList中,然后尝试使用该数据填充fooObjList . getAvatar 函数用于从firebase存储中获取imageUrl(avatarUrl),并返回图像的下载URL . 但是,当我尝试它; avatarUrl is returned undefined

此外,console.log("avatarUrl :" avatarUrl)显示未定义 .
但是,console.log("downloadUrl :" url)显示了我需要的下载URL .

Here is the console output

avatarUrl :undefined   
downloadUrl :https://firebasestorage.googleapis.com/v0/....000

如何将此URL添加到列表中?

我填充fooObjList的代码:

fooList: Observable<any[]>;
fooObjList: foo[] = [];    
storage = firebase.storage();
storageRef = this.storage.ref();

constructor(public navCtrl: NavController, public dataProvider: DataProvider, afDatabase: AngularFireDatabase, afStorage: AngularFireStorage) {            
        this.fooList= afDatabase.list('/foos').valueChanges();
        this.fooList.forEach(arr => {
          arr.forEach(item => {
            var avatarUrl = this.getAvatar(item.avatar);
            console.log("avatarUrl :" + avatarUrl);
            this.fooObjList.push(new foo(item.name, avatarUrl, item.tags));
          })
        })

getAvatar函数如下 .

getAvatar(img: string) {
    this.count++;
    if (this.count <= this.limit) {
      var tangRef = this.storageRef.child('avatars/' + img);
      tangRef.getDownloadURL().then(function (url) {
        console.log("downloadUrl :" + url);
        return url;
        //var img = document.getElementById('myimg').setAttribute('src', url);
      }).catch(function (error) {
        // Handle any errors
      });
    }
  }

我的foo类如下

export class foo{
    name: string;
  avatar: string;
  tags: string[];

  constructor(name: string, avatar: string, tags: string[]) {
      this.name = name,
      this.avatar = avatar,
      this.tags = tags
  }
}