Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何等待调用方法直到观察者工作?_Angular_Typescript2.0_Angular6 - Fatal编程技术网

Angular 如何等待调用方法直到观察者工作?

Angular 如何等待调用方法直到观察者工作?,angular,typescript2.0,angular6,Angular,Typescript2.0,Angular6,我有一些可观察的功能: 函数a():可观察的{} 函数b():可观察的{} 在我将这些观察值加入其中之后: 让waitingobserver=[a(),b()]; 公共getobserves(){ forkJoin(等待观察者)。订阅(结果=>{ 返回结果; }); } 我调用的最后一个函数是: 函数开始(){ if(this.currentForm().functions){ this.currentForm().functions.iterate(); this.currentForm(

我有一些可观察的功能:

函数a():可观察的{}
函数b():可观察的{}
在我将这些观察值加入其中之后:

让waitingobserver=[a(),b()];
公共getobserves(){
forkJoin(等待观察者)。订阅(结果=>{
返回结果;
});
}
我调用的最后一个函数是:

函数开始(){
if(this.currentForm().functions){
this.currentForm().functions.iterate();
this.currentForm().functions.getObservables();
}
/*返回下一张表格*/
this.current=nextForm;
}
此函数检查是否退出任何要调用的可观察方法,然后调用
This.currentForm().functions.iterate()

在第行对它们进行子订阅之后:
this.currentForm().functions.getObservables()

如何在所有可观察对象返回结果时等待此过程,然后调用:
this.current=nextForm

我的问题是:

  • 如果存在可观察的列表,则调用它们,然后执行第行:
    this.current=nextForm

我会将您的分叉流进一步传输到start函数

public getObservables():Observable<[X,Y]>{
    return forkoin(awaitingObservers);
}
我为什么要那样做? 方法“getObservables”只是一种方便的分叉方法。它不是真正的数据处理器。 结果的处理器位于“开始”函数中。我认为处理器应该始终负责触发订阅。 因此,我会在start函数中进行订阅


热情问候

我可以在
forkJoin()
中回复Observer。然后订阅并在内部调用:
this.current=nextForm我的意思是:
publicGetObservables():Observable{returnforkJoin(this.waitingObservers)。subscribe(results=>{return obbservable.of(results);});}
Cool,你的意思是从Fork返回ISTABLY观测者,然后subscibe在此基础上如果一个观测者返回false,错误会是什么?我需要确保所有观察者都能顺利执行,如果一个观察者出问题,你就会失去所有结果。但是您可以像平常一样捕捉错误。
if (this.currentForm().functions) {
      this.currentForm().functions.iterate();
      this.currentForm().functions.getObservables().subscribe( data => this.current = nextForm)
    }
}