2017-10-19 157 views
1

我想通过异步管道加载ngfor服务数据,但我现在面临的一个问题: 这是我的组件:InvalidPipeArgument:'[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],[对象对象],

<app-book-list *ngFor="let app of apps | async | serachBox:searchBooksByName | filterSearch:showTechBooks:showMgmBooks:showFictionBooks " 
    [bookdetails]="app"></app-book-list> 

在此组件的应用程序是从何而来的服务。

在我component.ts文件:

 public apps= []; 
    ngOnInit() { 
    this.ServerService.getBookDetails() 
     .then((data)=>{ 
     this.apps = data; 
     }) 
    } 

而且下面是承诺:

getBookDetails(){

let promise = new Promise((resolve,reject)=>{ 
    return this.http.get('https://lib-http-ng.firebaseio.com/bookdetails.json') 
     .toPromise() 
     .then((res)=>{ 
      const data = Object.values(res.json()); 
      resolve(data[0]) 
     }) 

}) 
return promise; 

} 我得到有关异步管道错误。

1.

Type '{}' is not assignable to type 'Promise<any>'. 
+0

您的代码使用几个管道。哪个管道导致错误?什么值导致错误? –

+0

@GünterZöchbauer它应该''|异步',不应该吗? “管'AsyncPipe'” – Pac0

+0

你是对的。如果你删除了其他管道,你仍然会得到相同的错误。这会导致https://stackoverflow.com/help/mcve这对于SO问题中的代码通常是一个好主意。 –

回答

0
this.ServerService.getBookDetails() 
    .then((data)=>{ 
    console.log(data); 
    this.apps = data; 
    }) 

应该

this.apps = this.ServerService.getBookDetails() 

或删除| async

+0

如果我删除异步,那么我必须重新加载页面以显示数据。数据采用异步方式。 –

+0

在这种情况下,'this.ServerService.getBookDetails()'中可能有错误。第二种选择呢? –

+0

没有第二个选项不会工作。强制相同的行为。 –