angular - Trying to make a Angular2 service that updates Firebase and returns an Observable -
i want make method on service works angularfire2 , returns observable. want update counter (updating counter may not scalable example, not matter here). attempt service:
import { injectable } '@angular/core'; import { angularfire } 'angularfire2'; import { observable } 'rxjs/observable'; import 'rxjs/add/operator/map'; @injectable() export class myservice { constructor(private af: angularfire) { } updatecounter(): observable<any> { let counterobserver = this.af.database.object('/variousdata/counter'); counterobserver.take(1).subscribe(res => { let counter = res.$value; return this.af.database.object('/variousdata').update({counter: counter+1}); }); return counterobserver; } }
and using this:
let resultobservable = this.myservice.updatecounter(); resultobservable.subscribe( (obj) => { console.log('result:', json.stringify(obj)); } }
but getting first result (getting counter value) printed console. how can (or only) second one?
i have been inspired example found in observable type 2 http.get calls in angular 2, example did not work firebase case, have tried alter it...
Comments
Post a Comment