【发布时间】:2017-08-20 13:37:50
【问题描述】:
我一直在尝试从节点获取对象数组到服务 onInit 并将其分配给组件。我可以查看服务中的数据,但是当我尝试分配给组件中的变量时,出现以下错误。我也包含了我的代码。请支持这一点。我只需要从服务中获取该数组并将其分配给组件中的决赛名单。
ERROR in
C:/Users/girija/Documents/animapp/src/app/components/list.component.ts (28,5): Type 'Subscription' is not assignable to type 'any[]'.
Property 'includes' is missing in type 'Subscription'.
我的代码如下: 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();
}
【问题讨论】:
标签: javascript angular angular2-services angular-http