【发布时间】:2019-07-24 12:42:33
【问题描述】:
我有一个父 observable 和两个 child observable,他们从父响应中获取 trialId 并自己进行 http 调用。我尝试使用mergeMap,但它给我的错误是它不是一个函数。我怎么能这样做?
private _trialListPoll$ = timer(0, this.listRequestInterval).pipe(
this.trialDataService.getTrailForPatient(this.patientId).mergeMap(
(data) => {
if (data.result.length > 0) {
const trial = data.result[0] as TrialPhase;
this.trialId = trial.trialId;
this.trialStartDate = trial.startDate;
this.trialEndDate = trial.endDate;
this.trialData$.next(data.result[0]);
this.loadDailyQuestionaireAnswerData(this.trialId); // child which makes http call and being subscribed somewhere
this.loadStartEndQuestionaireData(this.trialId); // child which makes http call and being subscribed somewhere
} else {
this.trialStartDate = undefined;
this.trialEndDate = undefined;
this.trialData$.next(undefined);
}
this.isQuestionnaireInDateRange();
this.isLoadingTrial$.next(false);
}
),share());
【问题讨论】:
-
你应该
pipe(mergeMap))。 Observable 上只有pipe作为函数存在。 -
啊好的,但现在它根本不起作用......我想我在这里遇到了类型问题
-
对于
mergeMap,你需要返回一个observable。我认为您应该将mergeMap替换为tap,它会起作用。 -
你能解决你的问题吗?
标签: angular rxjs observable