仅在返回 firestore 集合后执行操作

Carry out action only after firestore collection is returned

我正在订阅 firestore 中的一个集合。一旦返回值,我想对该数据执行一些操作。做这个的最好方式是什么?我遇到了一个类似的问题,导致我编写了下面的代码。但是,该代码似乎不会等到值出现。

this.versionCollection = this.FirebaseService.getCollection('versions', 'projectId', this.projectData.uid )
.subscribe(()=>{

    // Actions to be carried out after the data is returned
    this.versionData = this.versionCollection[this.versionCollection.length];
    this.initializeMenu();
    this.initializeModel();

});

afs为AngularFirestore的服务中调用的代码...

getCollection( collection, paramName, paramValue ) {
    return this.afs.collection( collection, ref => ref.where( paramName, '==', paramValue )).valueChanges();
}

一个简单的 if 检查就可以完成这项工作。

this.versionCollection = this.FirebaseService.getCollection('versions', 'projectId', this.projectData.uid )
    .subscribe(()=>{

        if(this.versionCollection) {
          this.versionData = this.versionCollection[this.versionCollection.length];
          this.initializeMenu();
          this.initializeModel();
        }

    });