带有Colcade异步问题的AngularFireStorage

问题描述

我在Firebase Storage中有一个图像文件夹,试图将其加载到Angular Web应用程序中,然后使用Colcade显示。我无法让Colcade的初始化代码仅在从Firebase Storage加载所有图像后才能运行。

我有一个服务,可以像这样检索所有图像的数组:

// Service
export class GalleryService {
  galleryList: String[];

  constructor(private afs: AngularFireStorage) {}

  async getGallery() {
    if (!this.galleryList) {
      let galleryList = [];
      const gallery = await this.afs.storage.ref('gallery').listAll();
      gallery.items.forEach(async (itemRef) => {
        galleryList.push(await itemRef.getDownloadURL());
      });

      this.galleryList = galleryList;
    }
    return this.galleryList;
  }
}

然后我从组件中调用以下代码:

// Component
export class MasonryComponent implements OnInit {
  galleryList: String[];

  constructor(private galleryService: GalleryService) {}

  ngOnInit(): void {
    this.getGallery();

    // This code is being run before the above finishes
    setTimeout(() => {
      if (this.galleryList) {
        this.galleryList.sort();
      }
      this.colcadeInit();
    },1000);
  }

  private async getGallery() {
    this.galleryList = await this.galleryService.getGallery();
  }

  private colcadeInit(): void {
    // selector string as first argument
    var colc = new Colcade('.grid',{
      columns: '.grid-col',items: '.grid-item',});
  }
}

我当前正在使用setTimeout来模拟代码应以其运行的顺序。但是,setTimeout的使用并不理想,因为图像的加载时间未知。请注意,此代码有效,Collcade或AngularFire的设置没有问题。

请帮助我,以便我的代码正常运行。谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...