protected hasLoadingError = false; protected loadUserData() { // set the loading flag when the request is initiated this.isLoadRequestInProgress = true; this.getUserData$() .pipe( finalize(() => { // clear the loading flag when the request completes this.isLoadRequestInProgress = false; }), catchError((error: HttpErrorResponse) => { // set the loading error flag this.hasLoadingError = true; return EMPTY; }) ) .subscribe(userData => { // clear the loading error flag this.hasLoadingError = false; // display the user data in the form this.updateForm(userData); }) }