Closed feischml closed 7 years ago
Hello @feischml, instead of return Object.assign( state, {associations: action.payload});
try return Object.assign({}, state, {associations: action.payload});
. This will create new object and wont mutate state. Also I would suggest to take a look and ngrx example app and usage of effects.
Hi @criticalbh, I tried also this, but the same result. I didn't introduce the effects for the sake of simplicity.
Also tried the following without success:
this.associations$ = this._store.select('associations');
...
getAssociationsDispatch(){
var route = '/associations/associations';
console.log("Calling action GET_ASSOCIATIONS");
this._http.get(
this.appConstants.getServerUrl() + route)
.map( associations => associations.json())
.map( payload => ({ type: associationActions.GET_ASSOCIATIONS, payload: payload}) )
.subscribe( action => this._store.dispatch(action));
console.log(this.associations$);
// here in the Store the desired values are there, see screenshot: associations: Array (2)
this.associations$.subscribe(res => console.log(res));
// here the result is: undefined - but why?
}
Hi, solved with:
this.associations$ = this._store.select(
(state:AppState) => {
return state.associations
}
).select('associations');
What the? can you chain select calls?
Hello,
I'm trying to make a simple example with ngrx but somehow don't get the wished result -> list items are undefined.
Here is my code:
Action:
Reducer:
export const initialState: AssociationState = { associations: [], selectedAssotiation: null };
export function assotiationsReducer(state = initialState, action: AssociationsActions.Actions) { switch (action.type) { case AssociationsActions.GET_ASSOCIATIONS: console.log(action.payload); //-> here I get the right results from the server: an array of objects return action.payload; default: return state; } ...
constructor(private _associationsService: AssociationService){ }
ngOnInit(){ this._associationsService.getAssociationsDispatch(); this.associations$ = this._associationsService.associations$;
}
Any ideas what could be missing?
Thank you, Laszlo