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?
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.
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With