我正在使用 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}`);
})
});
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}`);
})
)
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句