我没有在mergeMap中使用httpClient.get Observable获取任何数据

时间:2018-11-30 03:24:45

标签: angular rxjs 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 + '/' );
}

但是我没有从this.pData.getCommentsData(val.parent['id'], val.child['id']))

通过 console.log(val)获得任何数据

此外,来自this.route.parent.params的route.event,      this.route.params,除了起初不起作用。

route事件应始终有效。我的编码方式错误吗?

0 个答案:

没有答案
相关问题