Search code examples
angularngrx

Inject just ngrx feature state in a component


I have a feature state and I would like to inject it in a component. From all the examples that I saw there's only an option to have the global state inject which contains all the feature states. Is it possible to inject just a feature state into a component, and not the entire ngrx store?


Solution

  • When you inject Store, you will always have its full state. The generic on the store, e.g. FeatureState on Store<FeatureState>, is only to have type safety in that component at compile time. This is done for string selectors or function selectors, e.g. store.select(s => s.customers). If you're using selectors with the createSelector the generic typing isn't needed anymore, because the selectors themselves are type safe.

    At runtime, you will always get the full state.