Property 'includes' is missing in type 'Subscription' -angular2

那年仲夏 提交于 2019-12-08 18:28:27

subscribe returns Subscription object, this is not what you have looking for.

Try something like 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);
}

You should be using a map operator to convert the response into json type

getList(){
          return this.http.get('/api/list')
             .map(response=> <Type>response.json()) /////////
             .subscribe(data=>{
             this.finallist=JSON.parse(data['_body']);
             return this.finallist;
        })
        }

Note : <Type> is used for strict typing

See my answer below. It explains to you how to get your data from the server, to service, and finally to component. Receiving Jason instead of html. I am using mongodB but your backend may be different. Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!