Skip to content

Instantly share code, notes, and snippets.

@ByJC
Last active January 26, 2017 11:02
Show Gist options
  • Save ByJC/f0ae45df063c9ff1ad1033fb43deb984 to your computer and use it in GitHub Desktop.
Save ByJC/f0ae45df063c9ff1ad1033fb43deb984 to your computer and use it in GitHub Desktop.
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
import 'rxjs/add/observable/forkJoin';
@Component({
selector: 'example-fork-join',
templateUrl: 'fork-join.component.html'
})
export class ForkJoinComponent implements OnInit {
dataA: Array<Object> = [];
dataB: Array<number> = [];
dataC: Array<string> = [];
constructor(public http: Http) {}
ngOnInit() {
Observable.forkJoin([
this.http.get('http://www.server.com/dataA').map(res => res.json()),
this.http.get('http://www.server.com/dataB').map(res => res.json()),
this.http.get('http://www.server.com/dataC').map(res => res.json())
])
.subscribe(([A,B,C]) => {
this.dataA = A;
this.dataB = B;
this.dataC = C;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment