I have the following problem, when I call the getStudentsList function, it goes to the server to find the new values that I need, but the behaviorSubject returns the current value again (This causes me problems because it load the view with the previous values) while I wait for the server information to return. How can I do to avoid this behavior?
getStudentsList(params): Observable<StudentsListGrid> {
if (this.studentListSubject$ === undefined) {
this.studentListSubject$ = new BehaviorSubject<StudentListGrid>(null);
}
this.refetchStudentList(params);
return this.studentListSubject$.asObservable().pipe(filter((value) => value !== null));
}
refetchStudentList(gridParams) {
const subscription = this.http.post<StudentListGrid>(this.baseUrl + 'GetStudents', {gridParams} ,httpOptions).pipe(map(data => this.setDefaultValuesToStudent(data))).subscribe(
(response) => {
this.studentListSubject$.next(response);
subscription.unsubscribe();
});
}