I have a situation where I defined a variable diary: Diary
in my typescript file. When the user clicks a certain save button I have to execute f1
, a function having the following structure:
public f1() {
if (condition 1) {
this.service.serviceCall(param).subscribe(res =>
diary.firstPage.push(res)
)
}
if (condition 2) {
this.service.serviceCall(param).subscribe(res =>
diary.secondPage.push(res)
}
if (condition 3) { ... }
...
}
f1()
is executed before f2()
which does the following:
public f2() {
this.diaryService.saveDiary(diary).subscribe();
}
Since f1
modifies the diary
label, I have to make sure that f2
is executed only after all the subscriptions of f1
have been completed. How can I do that?