3

im using ngrx entity for my store the problem i cant select the store entities with selectors. i did as the code in this example https://github.com/angular-university/angular-ngrx-course/blob/master/src/app/courses/course.selectors.ts

in my situation when i use the select on the store i get the store object and not the entities.

this is my reducer:

reducer

this is the selectors: selectors

this is the component: enter image description here

this is the log from the select on the store, i expected a entities object and im getting this:enter image description here

this is the store:enter image description here

Alex Koretzki
  • 155
  • 2
  • 11

1 Answers1

1

The is because the selector is wrapped inside a function.

const selectAll = () => createSelector(selectFoo, entities.selectAll);

Therefore you have to call the function, to get the selector's data instead of the store.

this.data = this.store.select(selectAll());

But my question is why the selector is wrapped, this isn't really needed. You can do:

const selectAll = createSelector(selectFoo, entities.selectAll);

And in your component you can use it like you're using right now:

this.data = this.store.select(selectAll);

For more info, check out my article NgRx: Parameterized selectors

timdeschryver
  • 14,415
  • 1
  • 19
  • 32
  • im still getting the same output. the object of the store and not the entities. export const selectEstateOwnersState = createFeatureSelector('estateOwners'); export const selectAllEstateOwners = createSelector(selectEstateOwnersState, fromEstateOwner.selectAll); – Alex Koretzki Jan 06 '19 at 12:59
  • Keep in mind, that the selector returns an observable. If you log the `tblData`, you will get the observable. Use the async pipe in HTML to get the data, or use rxjs operators in the code if you just want to log the data. – timdeschryver Jan 06 '19 at 14:19
  • fwiw, the benefit of using the factory approach for selectors is to optimize ngrx's memo/caching behavior for selectors. From the [docs](https://ngrx.io/guide/store/selectors#using-selectors-with-props): "In order to correctly memoize the selector, wrap the selector inside a factory function to create different instances of the selector." Also since selectors with props are deprecated, a factory with params will be the new way to do selectors with props. – acat Jun 17 '21 at 13:02