Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Access state inside an ngrx effect
// In the Effect's constructor, inject store.
constructor(private store: Store<AppState>)
...
@Effect()
fetchUserProfile$: Observable<Action> = this.actions$.pipe(
ofType<FetchUserProfile>(UserActionTypes.FETCH_USER_PROFILE),
withLatestFrom(this.store),
mergeMap(([action, appState]) => {
return this.http
.get(
`${environment.apiUrl}/api/user/${appState.user.id}`
)
.pipe(
map((response: any) => {
return new FetchUserProfileSuccess(response.data);
}),
catchError(error => of(new FetchUserProfileFailure(error)))
);
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.