File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,10 @@ interface Course {
3636 <button (click)="httpPostExample()">POST Request</button>
3737
3838 <button (click)="duplicateRequestsExample()">Duplicate Requests</button>
39+
40+ <button (click)="parallelRequests()">Parallel</button>
41+
42+ <button (click)="sequentialRequests()">Sequential</button>
3943
4044 `
4145} )
@@ -186,4 +190,35 @@ export class AppComponent implements OnInit {
186190 this . courses$ = httpGet$ ;
187191 }
188192
193+
194+
195+ parallelRequests ( ) {
196+
197+ const parallel$ = Observable . forkJoin (
198+ this . http . get ( 'https://angular-http-guide.firebaseio.com/courses/-KgVwEBq5wbFnjj7O8Fp.json' ) ,
199+ this . http . get ( 'https://angular-http-guide.firebaseio.com/courses/-KgVwECOnlc-LHb_B0cQ.json' )
200+ ) ;
201+
202+ parallel$ . subscribe (
203+ values => {
204+ console . log ( "all values" , values )
205+ }
206+ ) ;
207+ }
208+
209+ sequentialRequests ( ) {
210+
211+ const sequence$ = this . http . get < Course > ( 'https://angular-http-guide.firebaseio.com/courses/-KgVwEBq5wbFnjj7O8Fp.json' )
212+ . switchMap ( course => {
213+
214+ course . description += ' - TEST ' ;
215+
216+ return this . http . put ( 'https://angular-http-guide.firebaseio.com/courses/-KgVwEBq5wbFnjj7O8Fp.json' , course )
217+ } ,
218+ ( firstHTTPResult , secondHTTPResult ) => [ firstHTTPResult , secondHTTPResult ] ) ;
219+
220+
221+ sequence$ . subscribe ( values => console . log ( "result observable " , values ) ) ;
222+ }
223+
189224}
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ import {AppComponent} from './app.component';
66import 'rxjs/add/operator/do' ;
77import 'rxjs/add/operator/map' ;
88import 'rxjs/add/operator/shareReplay' ;
9+ import 'rxjs/add/operator/switchMap' ;
10+
11+ import 'rxjs/add/observable/forkJoin' ;
912
1013
1114
You can’t perform that action at this time.
0 commit comments