Assign an observable to an array in angular 4 -
i trying initialize array observable. compilation error saying:
component:
export class leaderboardcomponent implements oninit { leaderboardtabledata: array<leaderboardmodel>; constructor(private appstore: store<appstore>, private leaderboardservice: leaderboardservice) { this.leaderboardservice.getleaderboard() .skipwhile((data) => { return _.isempty(data) }) .subscribe((data) => { if (!_.isempty(data)) { this.leaderboardtabledata = this.leaderboardservice.getleaderboard(); } }); }
service:
getleaderboard(): observable<leaderboardmodel> { return this.httputil.get(this.appconstants.end_point_leaderboard) .map(response => <leaderboardmodel>response.json()); }
getleaderboard()
method returns observable of single leaderboardmodel
element. upon subscription have push subscribed value (which data
) leaderboardtabledata
in component.
i think should be:
.subscribe((data) => { if (!_.isempty(data)) { this.leaderboardtabledata = [data]; // or `this.leaderboardtabledata.push(data);` , have make sure `leaderboardtabledata` instantiated though } });
Comments
Post a Comment