不推荐使用forkJoin:不推荐使用resultSelector,而是使用管道映射 [英] forkJoin is deprecated: resultSelector is deprecated, pipe to map instead

查看:550
本文介绍了不推荐使用forkJoin:不推荐使用resultSelector,而是使用管道映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事Angular 6项目.

I'm working on an Angular 6 project.

运行 ng皮棉会显示以下警告:

不推荐使用forkJoin:不推荐使用resultSelector,而是使用管道映射"

"forkJoin is deprecated: resultSelector is deprecated, pipe to map instead"

 forkJoin(...observables).subscribe(

有什么主意吗?似乎找不到有关此弃用的任何信息.

Any idea? Can't seem to find any information about this deprecation.

我刚刚使用Angular CLI:6.1.5生成了一个全新的Angular应用程序"ng new forkApp"

I just generated a brand new Angular application "ng new forkApp" with Angular CLI: 6.1.5

来源:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { forkJoin } from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'forkApp';

  constructor(private http: HttpClient) {}

  ngOnInit() {
    console.log('ngOnInit...');

    const obs = [];
    for (let i = 1; i < 4; i++) {

      const ob = this.http.get('https://swapi.co/api/people/' + i);
      obs.push(ob);

    }

    forkJoin(...obs)
      .subscribe(
        datas => {
          console.log('received data', datas);
        }
      );

  }
}

package.json文件中的

依赖项"部分:

"dependencies" section from package.json file:

  "dependencies": {
    "@angular/animations": "^6.1.0",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/router": "^6.1.0",
    "core-js": "^2.5.4",
    "rxjs": "^6.0.0",
    "zone.js": "~0.8.26"
  },

一旦完成所有三个操作,我就将所有数据保存在数据"数组中. 问题是,一旦我运行:ng lint,我就会得到:

Once all three gets are done I got all data in "datas" array. The issue is that once I run: ng lint I got this:

C:\ forkApp> ng皮棉

C:\forkApp>ng lint

警告:C:/forkApp/src/app/app.component.ts [26,5]:forkJoin是 不推荐使用:resultSelector不推荐使用,而是通过管道映射到

WARNING: C:/forkApp/src/app/app.component.ts[26, 5]: forkJoin is deprecated: resultSelector is deprecated, pipe to map instead

推荐答案

我能够通过消除省略号来解决此问题:

I was able to fix this by getting rid of the ellipsis:

forkJoin(observables).subscribe();

只要observables已经是一个数组,它应该具有相同的结果.

As long as observables is already an array, it should have the same result.

这篇关于不推荐使用forkJoin:不推荐使用resultSelector,而是使用管道映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆