[英]Angular 7 rxjs/forkJoin : You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
logic component.js file in below.下面的逻辑 component.js 文件。
ngOnInit() {
const join= forkJoin( this.getReconciliationData()); //import { forkJoin } from 'rxjs/internal/observable/forkJoin';
const subscribe= join.subscribe(result=>this.setReferenceTableData()); //Getting issue here
}
getReconciliationData() {
this.commonService.getMasterData(MaterDataType.LOCALREFERENCES).subscribe(result=>{
this.categories=result;
this.categories.forEach(c => {
c.children.forEach(subC => {
this.references.push(...subC.references);
});
this.subCategories.push(...c.children);
});
});
}
setReferenceTableData=function(){
this.dataSource=new MatTableDataSource(this.references);
}
While execution time getting an error.执行时出错。
***core.js:7187 ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
at Object.push../node_modules/rxjs/internal/util/subscribeTo.js.exports.subscribeTo (subscribeTo.js:29)
at Object.from (from.js:11)
at _loop_1 (forkJoin.js:42)
at Observable._subscribe (forkJoin.js:67)
at Observable.push../node_modules/rxjs/internal/Observable.js.Observable._trySubscribe (Observable.js:44)
at Observable.push../node_modules/rxjs/internal/Observable.js.Observable.subscribe (Observable.js:30)
at MedicalfileInternalServiceModelComponent.ngOnInit (medicalfile-internal-service-model.component.ts:69)
at checkAndUpdateDirectiveInline (core.js:24503)
at checkAndUpdateNodeInline (core.js:35163)
at checkAndUpdateNode (core.js:35102).***
. . I Think here looking return object from getReconciliationData() function.我认为这里从 getReconciliationData() 函数寻找返回对象。 But in my case not required return statement.但在我的情况下不需要 return 语句。 Anyone please help us for this issue.任何人请帮助我们解决这个问题。 I need to one by one function execution.我需要一一执行功能。
forkJoin
expects array. forkJoin
需要数组。
Try like this:像这样尝试:
const join= forkJoin( [this.getReconciliationData()])
Try like below modified code .尝试如下修改后的代码。 And i don't think you need forkJoin since you have only one observable而且我认为你不需要 forkJoin 因为你只有一个可观察的
ngOnInit() {
const subscribe = this.getReconciliationData().subscribe(result => {
this.categories = result;
this.categories.forEach(c => {
c.children.forEach(subC => {
this.references.push(...subC.references);
});
this.subCategories.push(...c.children);
});
this.setReferenceTableData();
}
};
getReconciliationData(): Observable<any> {
return this.commonService.getMasterData(MaterDataType.LOCALREFERENCES);
}
setReferenceTableData=function(){
this.dataSource=new MatTableDataSource(this.references);
}
Your getReconciliationData()
method returns nothing and it should return an Observable
which you want to pass to the forkJoin()
method.你的getReconciliationData()
方法什么都不返回,它应该返回一个你想传递给forkJoin()
方法的Observable
。 But are you sure you need to use it when you have only one thing to subscribe to?但是,当您只有一件事要订阅时,您确定需要使用它吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.