Can you tell me how to wait till one subscription is being finished?
Note: I need to wait till this let survey = this.getSurveys(currentQuestionCode)
is being finished.After that this return this.question = value;
should be executed. Here items are getting from the JSON array.
Update: My question is different than the mentioned duplicate issue.The question here is how to wait till 2nd observable has finished its work.
page.ts
getQuestions(currentQuestionCode: string): any {
this.surveyData.getQuestions().subscribe(
result => {
_.forEach(result, (value, key) => {
if (key == currentQuestionCode) {
let survey = this.getSurveys(currentQuestionCode);//here is the issue
return this.question = value;
}
});
},
err => { },
() => { }
);
}
getSurveys(currentQuestionCode: string): any {
this.surveyData.getSurveys().subscribe(
result => {
_.forEach(result, (value, key) => {
if (key == currentQuestionCode) {
return this.survey = value;
}
});
},
err => { },
() => { }
);
}
Service.ts
//get Questions
getQuestions(): Observable<any> {
return this.http.get("/assets/data/questions.json")
.map(this.extractData)
.catch(this.handleError);
}
//get Surveys
getSurveys(): Observable<any> {
return this.http.get("/assets/data/survey.json")
.map(this.extractData)
.catch(this.handleError);
}