I decided to use Observable instead of Http promises.
That is how my Promise service looked:
export class MovieService {
movies: Movie[]
mov
I suppose you should use map
method instead of subscribe
which returns Subscription
object
export class MovieService {
movies: Movie[];
movie: Movie;
constructor(private http: Http) {}
getMovies(): Observable<Movie[]> {
return this.http.get('http://api.request.com')
.map((res: Response) => res.json()['results']);
}
getMovie(id: number): Observable<Movie> {
return this.getMovies()
.map(movies => movies.find(movie => movie.id == id));
}
}
Plunker Example