angular: ngrx effects not firing

前端 未结 1 1481
一向
一向 2021-01-12 11:12

I\'ve worked on a few Angular apps that implemented Redux (NgRx). I can\'t figure out my current project\'s issue.

Actions:

export class GetUserFromS         


        
相关标签:
1条回答
  • 2021-01-12 12:00

    Make sure you have actually "activated" them.

    Effects injectable:

    @Injectable()
    
    export class FooEffects {
    
      @Effect() getUserFromStorage$:
    Observable<userActions.GetUserFromStorageSuccess | userActions.GetUserFromStorageFail>
        = this.actions$.pipe(
            ofType(userActions.UserActionTypes.GetUserFromStorage),
            tap(() => console.log('GETUserToStorage$', )),
            mergeMap((action: userActions.GetUserFromStorage) =>
                this.storageService.getItem(StorageKeys.USER).pipe(
                    map((user: User | null) =>
                        new userActions.GetUserFromStorageSuccess(user)),
                    catchError((error: string) =>
                        of(new userActions.GetUserFromStorageFail(error)))
                    ))
                );
    }
    

    app.module.ts:

    import {EffectsModule} from '@ngrx/effects';
    
    imports: [
      EffectsModule.forRoot([
        FooEffects
      ])
    ]
    
    0 讨论(0)
提交回复
热议问题