Skip to content

Instantly share code, notes, and snippets.

@tuanngominh
Last active October 29, 2018 07:41
Show Gist options
  • Save tuanngominh/c6e9841d4015b4802ea88e9af6b575f1 to your computer and use it in GitHub Desktop.
Save tuanngominh/c6e9841d4015b4802ea88e9af6b575f1 to your computer and use it in GitHub Desktop.
combineLatest with realtime database
// rxjs 5.4
// angularfire2-4.0.0-rc.1
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import 'rxjs/add/observable/combineLatest';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class Service {
constructor( private db: AngularFireDatabase ) {}
subscribe(id: string): Observable<any> {
// source1$ and source2$ are continuously emitting data over time
const source1$ = this.db.object(`path1/${id}`);
const source2$ = this.db.object(`path2/${id}`);
return Observable.combineLatest(
source1$,
source2$
)
.map([data1, data2] => logicToCombineData(data1, data2));
}
}
@Ross-Rawlins
Copy link

I tried this but the map never fires?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment