forkjoin后无法订阅 [英] Unable to subscribe after forkjoin
问题描述
我想在角度循环内执行一些firebase操作.当我向Firebase发送HTTP请求时,它返回一个可观察对象数组,因此使用forkjoin将这个可观察对象数组转换为单个可观察对象.现在的问题是,当我订阅这些新的观测值时,我什么都没得到
get_student_email(){this.get_project_service.get_project_by_doc_id(this.batchID,this.projectID).subscribe((res)=> {this.response = res;this.email = this.response.student;让数据= this.email.map((email)=>this.get_student_service.get_student_by_email_id(电子邮件));让信息= forkJoin([数据]);console.log('info:',info);info.subscribe((res)=> {console.log(res);console.log('Execute');});});}输出:信息:可观察的{_isScalar:false,_subscribe:ƒ}
我也尝试这个.在这次,它再次返回可观察值
let data = this.email.map((email)=>this.get_student_service.get_student_by_email_id(电子邮件));让信息= forkJoin([数据]);console.log('info:',info);info.subscribe((res)=> {console.log(res);console.log('Execute');});});输出:-信息:可观察的{_isScalar:否,_subscribe:ƒ}[可观察]执行
这是我的服务
get_student_by_email_id(电子邮件){返回this.fire_store.collection('User',(ref)=> ref.where('email','==',email)).valueChanges();}
我不知道此问题背后的主要原因是什么.我想要的是,在循环完成执行之后,它返回单个数组对象,该对象包含有关该电子邮件数组(this.email)的所有用户的信息
问题出在代码 forkJoin([data])
.
您的 data
已经是一个Observable数组,因此您可以像这样将其传递给 forkJoin
: forkJoin(data)
.>
I want to perform some firebase operation inside a loop in angular. When I send an HTTP request to firebase it returns an array of observables so using forkjoin i convert this array of observables into single observables. Now the problem is when I subscribe to these new observables I didn't get anything
get_student_email() {
this.get_project_service
.get_project_by_doc_id(this.batchID, this.projectID)
.subscribe((res) => {
this.response = res;
this.email = this.response.student;
let data = this.email.map((email) =>
this.get_student_service.get_student_by_email_id(email)
);
let info = forkJoin([data]);
console.log('info:', info);
info.subscribe((res) => {
console.log(res);
console.log('Execute');
});
});
}
Output:info: Observable {_isScalar: false, _subscribe: ƒ}
I also try this. In this time it again returns observables
let data = this.email.map((email) =>
this.get_student_service.get_student_by_email_id(email)
);
let info = forkJoin([data]);
console.log('info:', info);
info.subscribe((res) => {
console.log(res);
console.log('Execute');
});
});
Output:-
info: Observable {_isScalar: false, _subscribe: ƒ}
[Observable]
Execute
Here is my service
get_student_by_email_id(email) {
return this.fire_store
.collection('User', (ref) => ref.where('email', '==', email))
.valueChanges();
}
I don't know what is the main reason behind this problem. What I want is that after loop complete its execution it return single array object contain information about all the user which belongs to that email array(this.email)
The problem is with the code forkJoin([data])
.
Your data
it's already an array of Observables, so you just pass it to forkJoin
like this: forkJoin(data)
.
这篇关于forkjoin后无法订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!