Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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
Angular2:无法对Observables.forkJoin的响应使用数组函数_Angular_Typescript - Fatal编程技术网

Angular2:无法对Observables.forkJoin的响应使用数组函数

Angular2:无法对Observables.forkJoin的响应使用数组函数,angular,typescript,Angular,Typescript,我已经编写了一个服务,它将连接多个http请求并并行调用它们,并处理它们返回的响应 每个http请求都将返回数据数组。最后,我希望将所有请求数据合并到单个数组对象中,并将其发送回组件。 请看下面的代码 服务.ts System(modelId: number[]): Observable<Array<any>> { let apiArray = new Array<any>(); for (let item of modelId) {

我已经编写了一个服务,它将连接多个http请求并并行调用它们,并处理它们返回的响应

每个http请求都将返回数据数组。最后,我希望将所有请求数据合并到单个数组对象中,并将其发送回组件。 请看下面的代码

服务.ts

 System(modelId: number[]): Observable<Array<any>> {
    let apiArray = new Array<any>();
    for (let item of modelId) {
        apiArray.push(this.http.get("http:localhost/myService/models/" + item)
            .map((res) => {
                return this.extractData(res).items.map(({ id, name }) => new SystemModel(id, name, item));
            }))
    }
    let SysInModel: any = [];

    let result = Observable.forkJoin(apiArray).subscribe((results: Array<any>) => {

        results.forEach((item) => {
            let items: Array<any> = JSON.parse(JSON.stringify(item));
            items.forEach((k) => {
                SysInModel.push(k);
            })
        })
    });
    return Observable.of(SysInModel);
}
this.lookupService.System(_model)
        .subscribe((data) => {
            console.log(data);
            this.searchPanel.Systems = data;
            for (let item of this.searchPanel.Systems) {
                console.log(item);
            }

        },
        error => this.ShowError(error),
        () => { console.log('done'); });
在这个组件代码中,我在服务响应上编写的循环不起作用


谢谢你的帮助。提前感谢。

您能给我们一个您尝试运行阵列操作的示例吗?请参阅下面的组件代码。this.lookupService.System(_model).subscribe((数据)=>{console.log(数据);this.Systems=data;for(让this.searchPanel.Systems的项){console.log(项);}}},error=>this.ShowError(error),()=>{console.log('done');});@Eeks33我已经用组件代码更新了问题。请检查,因此console.log(data)是您正在显示屏幕截图的转储,并且您的错误在for of循环中?@Eeks33-是的,我无法对服务返回的结果进行操作。