下面的逻辑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);
}
执行时间出错。
***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).***
。我认为这里从getReconciliationData()函数中查找返回对象。但就我而言,不需要返回声明。 任何人都可以帮助我们解决这个问题。我需要一对一的函数执行。
答案 0 :(得分:0)
forkJoin
需要数组。
尝试这样:
const join= forkJoin( [this.getReconciliationData()])
答案 1 :(得分:0)
尝试下面的修改代码。而且我认为您不需要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);
}
答案 2 :(得分:0)
您的getReconciliationData()
方法不返回任何内容,它应该返回一个Observable
,您希望将其传递给forkJoin()
方法。但是,您确定只有一件事要订阅时需要使用它吗?