ForkJoin Issue on angular

隐身守侯 提交于 2021-02-19 05:44:18

问题


I make this code for test forkJoin but it does not work! Can you check what is the problem?

const observables = [];

observables.push(new Observable(subscriber => subscriber.next('Hello')));
observables.push(new Observable(subscriber => subscriber.next(' ')));
observables.push(new Observable(subscriber => subscriber.next('World') ));
observables.push(new Observable(subscriber => subscriber.next('!')));

forkJoin(observables).subscribe(word => console.log(word.join('')));

回答1:


Try this

const observables = [];

observables.push(Observable.of('Hello'));
observables.push(Observable.of(' '));
observables.push(Observable.of('World'));
observables.push(Observable.of('!'));

Observable.forkJoin(observables).subscribe(word => console.log(word.join('')));



回答2:


Is important complete the observable for forkJoin work, like the example!

const observables = [];

observables.push(new Observable(subscriber => {
  subscriber.next('Hello');
  subscriber.complete();
}));
observables.push(new Observable(subscriber => {
  subscriber.next(' ');
  subscriber.complete();
}));
observables.push(new Observable(subscriber => {
  subscriber.next('World');
  subscriber.complete();
}));
observables.push(new Observable(subscriber => {
  subscriber.next('!');
  subscriber.complete();
}));
forkJoin(observables).subscribe(word => console.log(word.join('')));


来源:https://stackoverflow.com/questions/48300456/forkjoin-issue-on-angular

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!