I'm struggling with using the Rxjs library, particularly when working with Observables:
In my Angular 2 application, I make API calls using the HTTP library which returns Observables.
The issue arises when I need to update a user:
function updateUser(user: User) {
return this.http.put("http://myAPI/user/update", user)
}
What I want is to automatically update the user every time the "updateUser" function is called, without having to do it manually in the calling side like this:
function updateUser(user: User) {
return this.http.put("http://myAPI/user/update", user).addCallback( updatedUser => {
this.user = updatedUser.json()
})
}
In simple terms, I am looking for a way to have a function executed every time "updateUser()" is subscribed. Is there a solution for this?
Thank you for your assistance!