[오류 : NgFor는 배열과 같은 반복문에만 바인딩을 지원합니다. ]ArrayQuery 함수 GraphQL에서 Observable을 반환하지만 * ngFor 오류가 발생했습니다
내가 뭘 잘못하고 있니?
View Code :
<div *ngFor="let item of data| async" class="wide-box">
구성 요소 코드 :
public data : ApolloQueryObservable
는
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)
})
는 서버에서 데이터를 다시 반입하려면 watchQuery 함수를 호출하고지도 기능의 일부 사후 처리를 수행하고, 배열의 관찰 가능한 반환
public refresh(){
this.data.refetch()
}
나는 단지 http://dev.apollodata.com/angular2/queries.html#합니다 ([문서]에 몇 분을 소비 한 this.data가 null로 채워집니다 가능성이 높습니다 select-pipe)하지만 당신의 모든 접근 방식은 완전히 그럴듯한 것 같습니다. 예를 들어 비동기 파이프로 작업하는 섹션에 직접 연결 한 것입니다. 예상했던대로, 문서화는 : 1. ngOnInit() 훅에서 watchQuery를 설정하는 것을 분명히 권고한다. 2. 함수에서 직접 observable을 깨끗하게 리턴한다. '.map()'처리가 실제로 구조를 망치는 것처럼 보입니다. 특히'x.data.user [0]'는 정말로 틀린 것 같습니다. –