Angular 将concatMap结果传入rxjs中的下一个concatMap
你可以看到我有一个方法,正如我所期望的那样工作良好Angular 将concatMap结果传入rxjs中的下一个concatMap,angular,rxjs,Angular,Rxjs,你可以看到我有一个方法,正如我所期望的那样工作良好 loadTemplates(configUrl: any, templateId: string): Observable<any> { this.getConfiguration(configUrl) .pipe( concatMap(configResponse => this.getTemplate( CONFIGURATION_URL +
loadTemplates(configUrl: any, templateId: string): Observable<any> {
this.getConfiguration(configUrl)
.pipe(
concatMap(configResponse =>
this.getTemplate(
CONFIGURATION_URL +
"templates/" +
configResponse.TemplateSettings.RootTemplate.Path,
configResponse
)
),
concatMap(rootTemplate =>
this.templateEngine.getAllChildTemplates(rootTemplate)
),
concatMap(childTemplates=>this.templateEngine.createTemplateToRender(childTemplates,""))
)
.subscribe(finalresponse=> {
debugger;
});
}
}
是否有正确的方法将根模板从管道本身传递到下一个concatMap?我不确定这是不是正确的方法。您可以将内部可观测结果映射到当前响应和前一个响应的数组中:
concatMap(rootTemplate =>
this.templateEngine.getAllChildTemplates(rootTemplate).pipe(
map(childTemplates => [rootTemplate, childTemplates])
)
),
concatMap(([rootTemplate, childTemplates]) =>
this.templateEngine.createTemplateToRender(childTemplates, rootTemplate)
)
您只需将内部可观测结果映射到当前响应和前一响应的数组中:
concatMap(rootTemplate =>
this.templateEngine.getAllChildTemplates(rootTemplate).pipe(
map(childTemplates => [rootTemplate, childTemplates])
)
),
concatMap(([rootTemplate, childTemplates]) =>
this.templateEngine.createTemplateToRender(childTemplates, rootTemplate)
)