I'm using ngrx/effects in my Angular2 application and since the release of RC5 I'm getting errors. This is my code:
import { Injectable } from '@angular/core';
import { Effect, Actions } from '@ngrx/effects';
import { UserActions } from './user.actions';
import { LoginService } from '../login';
constructor(
private updates$: Actions,
private userActions: UserActions,
private loginService: LoginService
) {}
@Effect() loadUser$ = this.updates$
.ofType(UserActions.LOAD)
.switchMap(() => this.loginService.loadUserData())
.map(user => this.userActions.loadUserComplete(user.userData));
The code above worked fine in Angular2 RC4 with ngrx/effects 1.1.1.
But when I upgraded Angular to RC5 I got the error: Unhandled Promise rejection: this.updates$.ofType(...).switchMap is not a function
I then upgraded ngrx/effects to the latest version 2.0.0-beta.2 (which according to the documentation should be customized for the new RC5 NgModule) but got the exact same error as above. And yes, i changed the whenAction()
functions to ofType()
in this step.
Any ideas?
You don't automatically have all RxJS operators imported in an angular 2 project. Did you try importing the switchMap
operator manually?
import 'rxjs/add/operator/switchMap';
This must exist somewhere in your code, probably it was imported by a third-party library before which doesn't import the operator any longer.
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