In some angular service, I need to call a PUT method named, I need to call another GET method once after it is completed. Then the results from GET method should be stored in a variable in the service itself.
The code which I have written has some issue with it. Because when I call the service from the component, isUpdateSuccess shown as undefined in the component.
Here, I do not need to pass the ‘application’ object to the component. I need to pass only the ApplicationStatusModel as an observable. But I need to save application object to a variable named myApplication as I mentioned above.
I read few articles and went through some Stackoverflow posts too. No luck yet.
Service
private myApplication: ApplicationHeader;
updateStudentAssessmentStatus(model: ApplicationStatusModel): Observable<boolean> {
const data = this.svcHttp.put<boolean>(`${this.routePrefix}/${model.studentID}/applicationAssessmentStatus`, model)
.pipe(
switchMap(() => this.getApplicationHeaderById(model.studentID)
.pipe(map(application => {
console.log(`Application from update status ${JSON.stringify(application)}`);
this.myApplication = application;
})))
);
return data;
}
component (which calls 'updateStudentAssessmentStatus')
this.svcApplication.updateStudentAssessmentStatus(statusModel).subscribe((isUpdateSuccess: boolean) => {
//isUpdateSuccess is NULL here.
if (!isUpdateSuccess) {
} else {
}
});