Questions tagged [ngrx-store]

Use this tag for questions related to the store package of the ngrx platform.

@ngrx/store is a controlled state container designed to help write performant, consistent applications on top of Angular. Core tenets:

  • State is a single immutable data structure
  • Actions describe state changes
  • Pure functions called reducers take the previous state and the next action to compute the new state
  • State accessed with the Store, an observable of state and an observer of actions

These core principles enable building components that can use the OnPush change detection strategy giving you intelligent, performance change detection throughout your application.

1216 questions
150
votes
6 answers

Angular 6 - Why use @ngrx/store rather than service injection

I am recently learning Angular 6 with @ngrx/store while one of the tutorial is to use @ngrx/store for state management, however I don't understand the benefit of using @ngrx/store behind the scene. For example, for a simple login and signup action,…
Drex
  • 3,346
  • 9
  • 33
  • 58
57
votes
4 answers

What is the difference between StoreModule.forRoot() and StoreModule.forFeature()

Recently ngrx store changed the way to register the store variables in an angular application. What is the difference between StoreModule.forRoot() and StoreModule.forFeature() Do we need to register both to make the application work?
Shanmugam M
  • 721
  • 1
  • 5
  • 10
43
votes
2 answers

Catch error in combined pipe of pipeable rxjs operators

We've just upgraded one of our applications to Angular 5, and started to transition into lettable operators as introduced in rxjs v5.5. Because of this, we have rewritten our observable pipelines to the new syntax with the .pipe() operator. Our…
Daniel B
  • 8,770
  • 5
  • 43
  • 76
34
votes
2 answers

NullInjectorError: No provider for ReducerManager

I am using the new ngrx 5. This is the file that holds the reducers and the featureSelector: import AppState from '../interfaces/app.state' import { ActionReducerMap, createFeatureSelector } from '@ngrx/store' import { partnerReducer } from…
suku
  • 10,507
  • 16
  • 75
  • 120
34
votes
3 answers

Angular 2+/4/5/6/7: Smart, dumb and deeply nested component communication

NOTE: for simplicity consider the component depths as: - Smart (grand)parent level 0 - dumb child level 1 .... - dumb grandchild level 2 ....) There are various options and conditions on how smart/grand/parent/child components…
MoMo
  • 1,836
  • 1
  • 21
  • 38
32
votes
4 answers

How to wait for 2 Actions in @ngrx/effects

Can effect wait two actions like Promise.all? Example: @Effect() pulic addUser() { return this.actions$.ofType(user.ADD) .switchMap(() => { return this.userService.add(); }) .map(() => { return new…
E. Efimov
  • 443
  • 1
  • 5
  • 10
31
votes
3 answers

what is ngrx createSelector and createFeatureSelector?

I have been reading the code of ngrx example app and find two function calls createFeatureSelector('auth'); and createSelector(selectAuthState,(state: AuthState) => state.status); What does this do? export const selectAuthState =…
Karty
  • 1,329
  • 6
  • 21
  • 32
31
votes
1 answer

Why must must ngrx / redux effects return actions? Is using a noop action like elm considered bad practice?

I'm using a redux-style state management design with Angular and ngrx/store and ngrx/effects. Whenever I don't return an action from an effect, I get an error: Cannot read property 'type' of undefined I researched the issue and found that in an…
Eeks33
  • 2,245
  • 1
  • 14
  • 17
27
votes
5 answers

Property 'payload' does not exist on type 'Action' when upgrading @ngrx/Store

I have the @ngrx/store package in my angular (4.x) app, and am upgrading from v2.2.2 -> v4.0.0. I can see that the migration notes say: The payload property has been removed from the Action interface. However, the example they give seems…
George Edwards
  • 8,979
  • 20
  • 78
  • 161
23
votes
4 answers

Angular 6 ngrx, how to add new item to array in state object?

I have a simple situation, I have actions Like CreatUser, CreateSuccess, CreateFail. How should I add new object to array and when Create action is dispatched or CreateSuccess? And how should I do that? export function reducer(state = init, action:…
Adam Adamski
  • 737
  • 3
  • 11
  • 20
23
votes
6 answers

How to unsubscribe from ngrx/store?

I have a component which gets its data from subscribing to a store. this.store.select('somedata').subscribe((state: any) => { this.somedata = state.data; }); I want to unsubscribe from this subscription when component is no more, in other places…
Uzair Khan
  • 2,812
  • 7
  • 30
  • 48
23
votes
1 answer

ngRx state update and Effects execution order

I have my own opinion on this question, but it's better to double check and know for sure. Thanks for paying attention and trying to help. Here it is: Imagine that we're dispatching an action which triggers some state changes and also has some…
Dmytro Garastovych
  • 335
  • 1
  • 2
  • 10
21
votes
2 answers

Independent instances of the same NgRx feature module

I am working on an Angular 5 project using NgRx 5. So far I've implemented a skeleton app and a feature module called "Search" which handles its own state, actions and reducers in an encapsulated fashion (by using the forFeature syntax). This module…
Stefan Orzu
  • 413
  • 4
  • 13
21
votes
1 answer

Ngrx Store Resets after browser refresh. How to make the application preserve the state?

I Dispatch a action from one component this.store.dispatch({type : STORE_TEAMCREST , payload : team.crestURI}); and in the other component i select from the store using this.store.select(state => state.table.teamCrest).subscribe(data =>…
INFOSYS
  • 1,465
  • 9
  • 23
  • 50
20
votes
1 answer

Warning from ngrx about runtime checks

I upgraded my app from Angular 7 to Angular 8 using ng update. When I run it via ng serve, There's a warning printed in my console from ngrx: @ngrx/store: runtime checks are currently opt-in but will be the default in the next major version with the…
fr0
  • 1,048
  • 2
  • 9
  • 16
1
2 3
81 82