简体   繁体   中英

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.

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. But in my case not required return statement. Anyone please help us for this issue. I need to one by one function execution.

forkJoin expects array.

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

  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. But are you sure you need to use it when you have only one thing to subscribe to?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Rxjs 6: using catchError() gives You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable Angular: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable Angular5 : TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable when deploying angular ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable in Angular Services TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable xplat You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable ERROR TypeError: You provided 'null' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM