flatMap missing after upgrading to RC 6 and RxJS Beta 11

后端 未结 2 1478
挽巷
挽巷 2021-01-18 10:36

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

flatMap operator is gone, mergeMap is also not here. I on

相关标签:
2条回答
  • 2021-01-18 11:04

    After upgrade to Angular 4, I've realized that now the correct way for importing flatMap is:

    import {Observable} from 'rxjs/Rx'
    import 'rxjs/add/operator/mergeMap';
    
    0 讨论(0)
  • 2021-01-18 11:10

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

    node_modules/rxjs/add/operator/mergeMap
    

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

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

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

    import 'rxjs/add/operator/mergeMap`;
    

    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.

    0 讨论(0)
提交回复
热议问题