How can i use the return values of 2 combined Observables in the next?
I need to fetch the settings and the current Position first before creating the map.
let trackerObservable = this.tracker.getCurrentPosition();
let settingsObservable = this.user.loadSettings();
Observable.merge(trackerObservable, settingsObservable)
.switchMap((coords: Coordinates, settings: Settings) => {
this.currentCoords = coords;
return this.navigatorMap.createMap(map_id, {
lat: coords.latitude,
lng: coords.longitude
}, settings);
}).subscribe(() => { [...] })
Use forkJoin
to get both the observable data.
Observable
.forkJoin(trackerObservable, settingsObservable)
.map((data: Array<any>) => {
let coords: data[0];
let settings: data[1];
this.currentCoords = coords;
return this.navigatorMap.createMap(map_id, {
lat: coords.latitude,
lng: coords.longitude
}, settings);
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加