我收到 [ 错误:NgFor 仅支持绑定到可迭代对象,例如数组。]
我究竟做错了什么?
View Code :
<div *ngFor="let item of data| async" class="wide-box">
组件代码:
public data : ApolloQueryObservable
调用watchQuery函数并在map函数中进行一些后期处理,并返回Array的Observable,
public feed(){
var a = gpl`
query user($user: UserInput){
user(user:$user){
first_name
lync{
artist
title
albumArtUrl
listenon
date
author{
username
email
}
}
following{
lync {
artist
title
albumArtUrl
listenon
date
author{
username
email
}
}
}
}
}
`;
this.data = this.apollo.watchQuery({
query: a,
variables: {
user: {
email: window.localStorage.getItem('email')
}
}
}).map((x:any)=>x.data.user[0]).map(x=>{
this.feedItem = []
if(x.lync.length){
x.lync.map(l=>{
if(l!=undefined){
this.feedItem.push(l)
}
})
}
if(x.following){
x.following.map(y=>{
if(y.lync.length != 0){
y.lync.map(l=>{
if(l!=undefined){
this.feedItem.push(l)
}
})
}
})
}
console.log(this.feedItem, "feedItem")
return ApolloQueryObservable.of(this.feedItem)
})
从服务器重新获取数据
public refresh(){
this.data.refetch()
}