Created
June 27, 2016 07:00
-
-
Save tkssharma/4bba53a974465dafa112c37ce51a9853 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Observable} from 'rxjs/Rx'; | |
@Injectable() | |
export class DemoService { | |
constructor(private http:Http) { } | |
// Uses http.get() to load a single JSON file | |
getFoods() { | |
return this.http.get('/app/food.json').map((res:Response) => res.json()); | |
} | |
// Uses Observable.forkJoin() to run multiple concurrent http.get() requests. | |
// The entire operation will result in an error state if any single request fails. | |
getBooksAndMovies() { | |
return Observable.forkJoin( | |
this.http.get('/app/books.json').map((res:Response) => res.json()), | |
this.http.get('/app/movies.json').map((res:Response) => res.json()) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment