I have angular app with a create function that adds a movie:
createMovie(movie: Movie): void {
this._dataService.createMovie<Movie>({'id': 20, 'name': 'Star Wars'})
.subscribe((data) => this.movie = data,
error => () => {
'something went wrong';
},
() => {
console.log(this.movies);
});
}
This calls the createMovie() function in the service:
public createMovie<T>(movie: Movie): Observable<T> {
console.log(movie);
return this.http.post<T>('/api/movies/', movie);
}
It's working fine. I can see that added object in the database and on a refresh on the page.
In my app.component.ts I have a movies: Movie[];
What is the correct way of adding the newly created movie to that array?