I have a method from a Provider that looks similar to this:
updateUser(user: User): Promise<User> {
return this.http.put<any>('url',JSON.stringify(user))
.toPromise()
.then((result) => {
this.eventsService.broadcast('userEdit:success', user)
return Promise.resolve(true);
})
.catch((err) => {
let errorData = {
error: err,
data: user
};
this.eventsService.broadcast('userEdit:failed', errorData)
return Promise.reject(errorData);
});
}
This does work and I do get the value of user
. But I believe that user
's value is expected to be gone which would cause an error? How does the variable user
retain it's value after the function updateUser
?
I wanted to have the user
's value back especially on the error catching so that I can notify and take the value to repopulate the form if I navigate back to it with the notification.
The current code works but I believe there is a better/correct way to do this to achieve the same objective. Please let me know how you would rather do it yourself.