![](/img/trans.png)
[英]Rxjs 6: using catchError() gives You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
[英]Angular 7 rxjs/forkJoin : You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
下面的邏輯 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() 函數尋找返回對象。 但在我的情況下不需要 return 語句。 任何人請幫助我們解決這個問題。 我需要一一執行功能。
forkJoin
需要數組。
像這樣嘗試:
const join= forkJoin( [this.getReconciliationData()])
嘗試如下修改后的代碼。 而且我認為你不需要 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);
}
你的getReconciliationData()
方法什么都不返回,它應該返回一個你想傳遞給forkJoin()
方法的Observable
。 但是,當您只有一件事要訂閱時,您確定需要使用它嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.