This is the method that I created:
getUser(endpoint: string, email: string) {
const url = this.envConfigurationService.baseEndpoint + '/' + conf.apiPrefix + '/' + endpoint + email;
this.loadingService.loadingOn();
return this.http.get(url).pipe(
finalize(() => this.loadingService.loadingOff()),
catchError((err) => {
this.manageError(err);
return throwError(err);
}),
tap(() => this.toastrService.success('OK')),
);
}
and here's how I call it in the component.ts:
searchUser() {
this.backendIntegrationService.getUser('user?code=', encodeURIComponent(this.form.value.email)).subscribe({
next: (res) => {
if (res['result'] === 'OK') {
this.userresponse = res['body'];
this.usermessage = res['message']
}
else {
this.errorResponse = res;
}
},
error: err => {
this.errorResponse = err;
}
});
console.log(this.userresponse)
this.entityConfiguration.inputFields.forEach(field => {
console.log(this.userresponse)
let value = null;
value = this.userresponse[field.name];
if (field.disabled) {
this.formControls[field.name] = this.fb.control({value: value, disabled: true});
} else {
this.formControls[field.name] = this.fb.control(value);
}
});
this.form = this.fb.group(this.formControls);
}
For some reason, the object this.userresponse only get populated at the second call (second time I push the search user button), even though I get the values from the backend at the first time.
What am I doing wrong?