角度可观察的返回对象Object

时间:2018-06-27 19:05:59

标签: angular

这可能是一个直接的答案,但是我在遵循有关http observables的教程时一直在绞尽脑汁。我从端点返回了以下数据格式:

{"result": [{"component": "UYT-3211"},{"component": "UYT-2121"}]}

我已经创建了一个组件模型,并使用搜索服务将数据拉回了

  results: Component[];

  search(component: string): Observable<Component[]> {
  let apiURL = `${this.apiRoot}?component=${component}`;
  return this.http.get(apiURL)
      .map(res => {
        return res.json().result.map(item => {
          console.log(item);
          return new Component();
      });
    });
  }

和搜索组件

  doSearch(component :string) {
   this.searchService.search(component).subscribe( data => {
     this.results = data 
   });
 }

console.log(item)的输出是我希望看到的,每个组件的json,但是当我打印出this.results时,我得到对象Object ..我期望有一个组件数组,所以我可以做<div *ngFor="let component of results"> </div>谁能阐明我在做什么错?赞赏。

0 个答案:

没有答案
相关问题