javascript - Property 'includes' is missing in type 'Subscription' -angular2 -
i have been trying array of objects node service oninit , assign component. able view data in service when try assign variable in component, below error. have included code well. please favour on this.all need take array service , assign finallist in component.
error in c:/users/girija/documents/animapp/src/app/components/list.component.ts (28,5): type 'subscription' not assignable type 'any[]'. property 'includes' missing in type 'subscription'.
my code below: app.service.ts:
public finallist=[] getlist(){ return this.http.get('/api/list').subscribe(data=>{ this.finallist=json.parse(data['_body']); return this.finallist; }) }
app.component.ts:
totallist=[]; ngoninit() { this.totallist=this.someservice.getlist(); }
subscribe
returns subscription
object, not have looking for.
try this:
app.service.ts
getlist(): observable<any> { return this.http.get('/api/list').map(data => data['_body']); }
app.component.ts
totallist=[]; ngoninit() { this.someservice.getlist().subscribe(data => this.totallist = data); }
Comments
Post a Comment