Last active
January 26, 2017 11:02
-
-
Save ByJC/f0ae45df063c9ff1ad1033fb43deb984 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 { 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