In ngOnInit
, my component obtains a list of users like so:
this.userService.getUsers().subscribe(users => {
this.users = users;
});
And the implementation of userService.getUsers() looks like this:
getUsers() : Observable<UserModel[]> {
return this.http.get('http://localhost:3000/api/user')
.map((res: Response) => <UserModel[]>res.json().result)
.catch((error: any) => Observable.throw(error.json().error || 'Internal error occurred'));
}
Now, in another component, I have a form that can create a new user. The problem is that when I use that second component to create a user, the first component doesn't know that it should make a new GET request to the backend to refresh its view of users. How can I tell it to do so?
I know that ideally I'd want to skip that extra HTTP GET request, and simply append the data the client already has from when it made the POST to insert the data, but I'm wondering how it'd be done in the case where that's not possible for whatever reason.