angular - AngularFire .subscribe => console.log returning undefined after use of map or flatMap -
i'm pretty new angularfire, firebase, rxjs etc..
can tell me why following returns 'undefined' console.log?
this.af.database.object('/teams/' + this.id) .map((data) => { data.teamname = teams[data.team]; }) .subscribe((data) => { console.log(data) })
teams enum. red = 1, blue = 2...
i know problem lies in .map if remove , log x or log enum lookup both work fine..
this works fine (and resolves red):
this.af.database.object('/teams/' + this.id) .subscribe((x) => { console.log(teams[x.team]); })
as (resolving firebase observable):
this.af.database.object('/teams/' + this.id) .subscribe((x) => { console.log(x); })
i've tried flatmap on list rather map on object.
any appreciated.
because returns both get
, map
methods observable, not json.
in
.map((data) => { data.teamname = teams[data.team]; })
you treat data
variable json isn't. variable becomes undefined. because there's no such thing data.teamname
ref: https://angular.io/docs/ts/latest/guide/server-communication.html#!#fetch-data
http.get method returns observable of http responses (observable) rxjs library , map 1 of rxjs operators.
Comments
Post a Comment