angularjsngrxngrx-storengrx-entity

how to use ngrx entity selectors?


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


Solution

  • 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