首页 > 解决方案 > 我没有在 mergeMap 中使用 httpClient.get Observable 获取任何数据

问题描述

这就是我所做的

constructor(
   private route: ActivatedRoute,
   private pData: PDataService,
) {
}

ngOnInit() {
   this.combine$ = combineLatest(
     this.route.parent.params,
     this.route.params,
   ).pipe(
     map(([parent, child]) => {
       return { parent, child };
     }),
     tap( val => {
     // did something
     ),
     mergeMap( val => this.pData.getCommentsData(val.parent['id'], val.child['id']))
   ).subscribe( val => console.log(val));
}

在 PDataService 中

getCommentsData(productId, reviewsId) {
   return this.httpClient.get<any>( this.BASE_URL + '/api/products/' + productId + '/reviews/' + reviewsId + '/' );
}

但我没有通过console.log(val)this.pData.getCommentsData(val.parent['id'], val.child['id']))

this.route.parent.params此外,来自, 的route.eventthis.route.params不工作,除非一开始。

路线事件应该始终有效。我编码错误吗?

标签: angularrxjsobservable

解决方案


推荐阅读