ngrx-store

How to dispatch an action with current value of state?

落爺英雄遲暮 提交于 2021-02-10 16:40:02
问题 I have an angular component showing items in a list. Each itemn can be selected and the ids of the selected items will be stored in the state. So my state object looks like this f.e.: { items: Item[]; selected: string[] } Now I got an action called DeleteSelectedAction that gets selected as payload. This action will call some WebAPI using an effect and so on. Now I found two ways how I could do this. First: Select selected from store and subscribe to it and pass the value with the action

Using payload of action on ActionsSubject subscription on NGRX

萝らか妹 提交于 2021-02-08 05:08:09
问题 I got the old and bad Property 'payload' does not exist on type 'Action doing this actions subscription: Since is a Creation Action, I need the payload to checkout the userId of the recently created User and navigate to /users/userId BTW: I'm following this really nice tutorial @Component({ selector: 'app-sample', templateUrl: 'sample.html', }) export class AppComponent { subs = new Subscription(); constructor(private actionsSubject: ActionsSubject) { this.subs = actionsSubject.subscribe

Getting error while registering reducers using ActionReducerMap: “not assignable to type 'ActionReducerMap<AppState, Action>”

天大地大妈咪最大 提交于 2021-02-04 22:43:50
问题 Below is simplified version of my Angular 5 application. I have a reducer, which I want to register in my root module. In LINE A I am getting following error: ERROR in src/app/store/app.reducers.ts(7,14): error TS2322: Type '{ post: (state: State, action: Action) => void; }' is not assignable to type 'ActionReducerMap<AppState, Action>'. Types of property 'post' are incompatible. Type '(state: State, action: Action) => void' is not assignable to type 'ActionReducer<State, Action>'. Type 'void

Getting error while registering reducers using ActionReducerMap: “not assignable to type 'ActionReducerMap<AppState, Action>”

橙三吉。 提交于 2021-02-04 22:43:04
问题 Below is simplified version of my Angular 5 application. I have a reducer, which I want to register in my root module. In LINE A I am getting following error: ERROR in src/app/store/app.reducers.ts(7,14): error TS2322: Type '{ post: (state: State, action: Action) => void; }' is not assignable to type 'ActionReducerMap<AppState, Action>'. Types of property 'post' are incompatible. Type '(state: State, action: Action) => void' is not assignable to type 'ActionReducer<State, Action>'. Type 'void

Get error response from ngrx@effects to component

狂风中的少年 提交于 2021-01-27 07:10:47
问题 I need to set server error validation for every input field in form. Problem is, I use ngrx@store and in effect I have @Effect({ dispatch: false }) error$ = this.actions$.pipe( ofType(actions.UserActionTypes.Error), map( (error: actions.Error) => { new actions.Error(error); } //this.notificationService.warn(error.error.message) ) ); With this code, I store errors to store. Now I need to get these errors in my component, where I want to check for which input field I get an error, and set error

Dispatch ngrx store action in route resolver

北城余情 提交于 2021-01-27 05:31:30
问题 I'm currently have a container (stateful) component which dispatches a select and a get action based on a route param (id) in the ngOnInit method. The point of these actions to have the data and the selected id in my store. I'm curious would it be correct to dispatch these actions in a resolver? Thanks for the replies. My component: @Component({ selector: 'app-container', templateUrl: './container.component.html', styleUrls: ['./container.component.css'] }) export class ContainerComponent

ngrx/store state not updating in reducer function called

痴心易碎 提交于 2020-01-25 00:48:27
问题 I am starting to add ngrx(8.4.0) to an existing Angular(8.2) application but one of my actions (see action below) when triggered does not mutate state. auth.actions.ts (partial) export const loginSuccess = createAction( '[SIGN IN] Login Success', props<{ user: any; isNewUser: boolean }>() The loginSuccess action is handled by the reducer function below. auth.reducer.ts (partial) export interface AuthState { user: any; isNewUser: boolean; } export const initialState: AuthState = { user: null,