这就是我所做的
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']))
此外,来自this.route.parent.params
的route.event,
this.route.params
,除了起初不起作用。
route事件应始终有效。我的编码方式错误吗?