Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created June 27, 2016 07:00
Show Gist options
  • Save tkssharma/4bba53a974465dafa112c37ce51a9853 to your computer and use it in GitHub Desktop.
Save tkssharma/4bba53a974465dafa112c37ce51a9853 to your computer and use it in GitHub Desktop.
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