Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flatMap missing after upgrading to RC 6 and RxJS Beta 11

Tags:

angular

rxjs

After upgrading to RC6 and [email protected] I seem to be missing a few extensions from Observable object.

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

enter image description here

like image 964
Yodacheese Avatar asked Sep 11 '16 23:09

Yodacheese


2 Answers

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.

like image 124
Paul Samsotha Avatar answered Nov 02 '22 16:11

Paul Samsotha


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';
like image 44
Lupe Avatar answered Nov 02 '22 16:11

Lupe