Reviewing and saving form data
On the last step of the multistep form, users should be able to review and then save the form data. As a good practice, a successful POST
request will return the data that was saved back to the browser. We can then reload the form with the information received back from the server:
src/app/user/profile/profile.component.ts
...
async save(form: FormGroup) {
this.userService
.updateUser(this.currentUserId, form.value)
.pipe(first())
.subscribe({
next: (res: IUser) => {
this.patchUser(res)
this.formGroup.patchValue(res)
this.uiService.showToast('Updated user')
},
error: (err: string) => (this.userError = err),
})
}
...
Note that updateUser
returns the saved value of the user. It is possible that the database returns a different version of user
than what we had before, so we use formGroup.patchValue
to update the data powering the form. The...