升级到 RC 6 和 RxJS Beta 11 后缺少 flatMap [英] flatMap missing after upgrading to RC 6 and RxJS Beta 11

查看:15
本文介绍了升级到 RC 6 和 RxJS Beta 11 后缺少 flatMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 RC6 和 rxjs@5.0.0-beta.11 后,我似乎缺少一些 Observable 对象的扩展.

After upgrading to RC6 and rxjs@5.0.0-beta.11 I seem to be missing a few extensions from Observable object.

flatMap 算子没了,mergeMap 也没有了.我现在只看到几个操作员.知道我错过了什么吗?

flatMap operator is gone, mergeMap is also not here. I only see a few operators now. Any idea what I'm missing?

推荐答案

我想现在您需要单独导入运算符.如果你往里面看

I guess now you need to import operators individually. If you look inside

node_modules/rxjs/add/operator/mergeMap

你应该看到 mergeMap.d.ts.其中的内容是

you should see mergeMap.d.ts. The contents of which are

declare module '../../Observable' {
    interface Observable<T> {
        flatMap: MergeMapSignature<T>;
        mergeMap: MergeMapSignature<T>;
    }
}

所以mergeMap 模块同时声明了flatMapmergeMap.所以你可以导入那个文件

So the mergeMap module declares both flatMap and mergeMap. So you can just import that file

import 'rxjs/add/operator/mergeMap`;

如果您担心样式(即必须在您需要的所有文件中导入它),您可以查看 Angular 教程,他们将应用程序需要的所有操作符导入到一个文件中,然后将该文件导入到 app.component 文件中.您应该只需要在一个地方导入它.根据我的经验,在不涉及 AppComponent 的单元测试时,我必须将该文件导入到每个测试文件中.

If you're concerned about style (i.e having to import this in all the files you need it), you can check out the plunker example from the Angular tutorial, where they import all the operators the application needs into a file, and just import that file into the app.component file. You should only need to import this in one place. From my experience, when unit testing, where the AppComponent is not involved, I had to import that file into each of the test files.

这篇关于升级到 RC 6 和 RxJS Beta 11 后缺少 flatMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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