ForkJoin角度问题

时间:2018-01-17 11:48:51

标签: angular rxjs rxjs5

我为test forkJoin制作了这段代码,但它不起作用! 你能检查一下是什么问题吗?

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('')));

2 个答案:

答案 0 :(得分:3)

试试这个

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('')));

答案 1 :(得分:0)

重要的是完成forkJoin工作的observable,就像示例一样!

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('')));