combineLatest弃用了静态combineLatest

问题描述 投票:13回答:3

使用后运行rxjs迁移工具

rxjs-5-to-6-migrate -p src / tsconfig.app.json

我现在得到一个linting错误:

combineLatest已弃用:不赞成使用static combineLatest。

在运行迁移命令之前,这是我的代码:

this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });

运行迁移命令后的代码:(当前显示linting错误)

import {map, combineLatest} from 'rxjs/operators';
this.store.combineLatest(
        this.store.select(lang.getCurrent),
        this.store.select(lang.getCurrentLocale)
    ).subscribe(([state, currentLang, locale]) => {
        this._language = session.language === currentLang ? '' : currentLang;
        this._locale = session.locale === locale ? '' : locale;
    });

问题在这个stackoverflow问题中被问到,但它不够具体:Angular 6 ng lint duplicate errors and warnings, combineLatest is deprecated

rxjs rxjs6
3个回答
42
投票

我在这篇文章中找到了一个答案:RxJS 6: What's new and what has changed?(来自official docs):

解决方案是转换:

import { combineLatest } from 'rxjs/operators';

a$.pipe(combineLatest(b$, c$));

成:

import { combineLatest } from 'rxjs';

combineLatest(a$, b$, c$);

9
投票

在rxjs 6.5中

import { combineLatest } from 'rxjs';
combineLatest([a$, b$, c$])


0
投票

rxjs版本6.4.0

你应该从RxJs运算符导入map运算符,它将起作用

combineLatest(a$, b$, c$).pipe(map([a, b, c]) => treat(a, b, c))
© www.soinside.com 2019 - 2024. All rights reserved.