In my Angular component, ngOnInit()I want:
- Read the route parameter and make a dependent HTTP call with it as an argument.
- Make a separate HTTP call.
- Wait for both HTTP calls to complete.
Both HTTP calls are always made, but when my first observable is connected before route.params, the method forkJoin(...).subscribe(...)never starts. If I replaced this.route.paramswith Observable.of({id: 1234}) forkJoin().subscribe(), it is called correctly.
var dependentObservable = this.route.params
.switchMap(params => {
this.myId = +params['id'];
return this.myService.getMyInfo(this.myId);
});
var dependentObservable = Observable.of({id: 123})
.switchMap(params => {
this.myId = +params['id'];
return this.myService.getMyInfo(this.myId);
});
var independentObservable = this.myService.getOtherInfo();
Observable.forkJoin([dependentObservable, independentObservable])
.subscribe(
results = { ... },
error => { ... },
() => { ... }
);
source
share