【发布时间】:2021-06-08 17:12:16
【问题描述】:
我需要订购一系列产品。但是 getProduct() 的工作时间比我需要的晚,并且所有产品都未定义。我发现嵌套订阅的方式不好,那么使用mergeMap/switchMap的正确方法是什么
getOrder(id: string) {
this.orderService
.getOrder(id)
.subscribe(order => {
order.map(item => {
data.push(item.payload.doc.data());
return data;
});
this.order = data[0].products.map(x => this.getProduct(x))
});
}
getProduct(id: string) {
return this.productService
.getProduct(id)
.subscribe(product => product);
}
getOrderById(id: string): Observable < any > {
return this.afs
.collection('orders', ref => ref.where('uid', '==', id))
.snapshotChanges();
}
getProductById(id: string): Observable < any > {
return this.afs
.collection('products', ref => ref.where('uid', '==', id))
.valueChanges();
}
【问题讨论】:
-
这能回答你的问题吗? Await recursive forkJoin in Angular
标签: angular rxjs subscription