Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngrx/effects switchMap no longer working in Angular2 RC5

Tags:

angular

ngrx

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?

like image 753
Weblurk Avatar asked Dec 19 '22 14:12

Weblurk


1 Answers

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.

like image 157
Andreas Jägle Avatar answered Jan 13 '23 06:01

Andreas Jägle