I am writing an Angular 4 application using HttpClient
that displays movie show times. There are 2 JSON files where the data is located: showtimes.json
and movies.json
.
// showtimes.json
[{
"id": "2030c64ce72b4e4605cb01f2ba405b7d",
"name": "Arclight", // need to display this information
"showtimes": {
"b4c2c326a4d335da654d4fd944bf88d0": [ // need to use this id
"11:30 pm", "2:45 pm", "8:35 pm", "4:15 pm", "10:30 pm"
]
}
}]
// movies.json
[{
"b4c2c326a4d335da654d4fd944bf88d0": { // to retrieve the title, rating, and poster
"title": "Fifty Shades Darker", // needs to be displayed
"rating": "R", // needs to be displayed
"poster": "https://dl.dropboxusercontent.com/s/dt6wgt92cu9wqcr/fifty_shades_darker.jpg" // needs to be displayed
}
}]
I have service that can retrieve the title
and name
of the theater. But now I must use the value in the showtimes
object to display the correct title name. As you see b4c2c326a4d335da654d4fd944bf88d0
is the id of the movie title and can be retrieved from the movies.json
file.
So far this is my component
ngOnInit() {
this._moviesDataService.getShowtimes()
.subscribe(res => this.results = res)
}
And this is my service.
getShowtimes (): Observable<ShowTimes> {
return this._http.get<ShowTimes>(this._showtimesURL)
}
My question is how do I retrieve the title
of the movie using its id? Would this require two chained Observables? Would I need to loop through the movies array and .filter
it?
I've included an example of what I am trying to build
forkJoin
and the variousmap
methods. – Samarium