TypeError Observable.concat不是函数

时间:2018-06-30 17:25:23

标签: angular rxjs observable

我需要连接一系列可观察对象,然后订阅它们

有功能

let arrayObservable: Array<Observable<any>> = new Array<Observable<any>>();

products
 .forEach(product => {
    arrayObservable.push(this.service.delete(product));
});
Observable.concat(arrayObservable)
 .subscribe(response => {
    console.log(response)
})

2 个答案:

答案 0 :(得分:1)

concatmergerxjs 中的静态函数。他们不在 Observable

示例:

import { concat, of} from "rxjs";
const n1 = of(1,2,3);
const n2 = of(4,5,6);
const cc = concat(n1, n2);
cc.subscribe(d=> console.log(d));

答案 1 :(得分:0)

您可以尝试使用此解决方案

import { concat } from 'rxjs/observable/concat';

export class AppComponent implements onInit {

    ngOnInit() {
        let arrayObservable: Array < Observable < any >> = new Array < Observable < any >> ();

        products
            .forEach(product => {
                arrayObservable.push(this.service.delete(product));
            });
        concat(arrayObservable)
            .subscribe(response => {
                console.log(response)
            })
    }
}