Razgort
Razgort

Reputation: 468

dynamic parameter ngrx selector

i'm a bit struggling here i have the following selector

export const selectMoMenuInfoByIdDynamic = createSelector(
selectMoMenuState,
state => (meId: string) => {
let currentMenu: MoMenu
console.log(state.MoMenuItems)
currentMenu = state.MoMenuItems.find(element => {
return element.ME_ID === meId
})
return currentMenu
}
)

but can't get it to work when i call it with

const moMenu = this.store.pipe(
select(selectMoMenuInfoByIdDynamic),
map(res => res(meId))
)
console.log(moMenu)

Any idea for me ?

Would be huge help Thanks in advance

Upvotes: 1

Views: 3772

Answers (1)

timdeschryver
timdeschryver

Reputation: 15507

There are several ways to create a parameterized selector, each have a use case. See my post Parameterized selectors for more info.

export const getCount = () => createSelector(
  getCounterValue,
  (counter, props) => counter * props.multiply,
)

// in components:

this.counter = this.store.pipe(select(fromRoot.getCount, { multiply: 2 }))

export const selectCustomer = (id: string) =>
  createSelector(
    selectCustomers,
    customers => customers[id],
  )

// in component

this.customer = store.pipe(select(customers.selectCustomer('47')))

Upvotes: 5

Related Questions