【问题标题】:Angular 7 rxjs/forkJoin : You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or IterableAngular 7 rxjs/forkJoin:您在预期流的位置提供了“未定义”。您可以提供 Observable、Promise、Array 或 Iterable
【发布时间】:2020-03-26 21:07:51
【问题描述】:

下面的逻辑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() 函数的返回对象。但在我的情况下,不需要返回声明。 请任何人帮助我们解决这个问题。我需要一个一个的函数执行。

【问题讨论】:

    标签: angular


    【解决方案1】:

    forkJoin 需要数组。

    试试这样:

    const join= forkJoin( [this.getReconciliationData()])
    

    【讨论】:

      【解决方案2】:

      试试下面的修改代码。而且我认为你不需要 forkJoin 因为你只有一个 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);
        }
      

      【讨论】:

        【解决方案3】:

        您的getReconciliationData() 方法不返回任何内容,它应该返回一个您想要传递给forkJoin() 方法的Observable。但是当您只有一件事要订阅时,您确定需要使用它吗?

        【讨论】:

        • 完全不需要。我试图避免异步执行 this.getReconciliationData() 和 this.setReferenceTableData() 函数一一执行..
        猜你喜欢
        • 2021-12-10
        • 2018-09-07
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 2017-09-18
        • 1970-01-01
        相关资源
        最近更新 更多