我正在使用Angular6,并尝试在此过滤器函数中获取文档内容。我的代码片段的最后一行给出了一个错误:“非类型化函数调用可能不接受类型参数”。不确定为什么我会收到这个错误...也许它不能在过滤函数中使用...?
构造函数:
constructor(private afs : AngularFirestore, private authService : AuthService) {
//Get user collection on initialise
this.userCollection = this.afs.collection('users');
}过滤:
this.userCollection = this.afs.collection<User>('users', ref => {
console.log(ref);
return ref
})
this.usersOnSearch = this.userCollection.valueChanges();
this.usersOnSearch.flatMap(user => {
return user.filter(function(value) {
let subjectTrue : boolean = false;
let levelTrue : boolean = false;
let docID : string = value.user_subjects.id;
let userLevelPriceDocument : AngularFirestoreDocument<UserSubjects>;
userLevelPriceDocument = this.afs.doc<UserSubjects>(`user_subjects/${docID}`);
})
});发布于 2018-07-23 04:32:40
flatMap签名需要返回一种类型的Observable<T>。在您的例子中,您只返回<T> (在您的例子中是any,因为这是控制输出)。尝试用Observable.of()包装返回值:
this.usersOnSearch.flatMap(user => {
return Observable.of( user.filter(function(value) {
let subjectTrue : boolean = false;
let levelTrue : boolean = false;
let docID : string = value.user_subjects.id;
let userLevelPriceDocument : AngularFirestoreDocument<UserSubjects>;
userLevelPriceDocument = this.afs.doc<UserSubjects>(`user_subjects/${docID}`);
})
)
});https://stackoverflow.com/questions/51468760
复制相似问题