Methodician / flight.run

2 stars 0 forks source link

Implement automatic way to work again with observables without AngularFire2 #98

Open Methodician opened 6 years ago

Methodician commented 6 years ago

I tried something like this and it seems to work:

listItemsRef(parent){ return firebase.database().ref(/${parent}/${parent}-slugs); }

subjectFromRef(ref: firebase.database.Reference): BehaviorSubject{ const subject = new BehaviorSubject(null); ref.on('value', snapshot => { const val = snapshot.val(); subject.next(val); }) return subject; }

In component:

const ref = this.featuredService.listItemsRef(this.parent); this.featuredService.subjectFromRef(ref).subscribe(res => console.log('RESULT', res));