Alex Koretzki
Alex Koretzki

Reputation: 157

how to use the ngrx store inside ngrx effect? i need data from store for making api call

i need to use my store inside effect but im getting error. what is the correct way to do so?

enter image description here

enter image description here

Upvotes: 0

Views: 1524

Answers (1)

Zyzle
Zyzle

Reputation: 2280

Since your selected state is itself an Observable you can combine this into your stream with the withLatestFrom operator.

This is a rough example but I think you're looking for something along the lines of:

@Effect()
loadEstateOwners$ = this.actions$.pipe(
  ofType(EstateOwnerListActionTypes.LoadEstateOwners),
  withLatestFrom(this.store.select('userProfile')),
  map(([actions, user]) => {
    // Do something ...
  })
);

More info on withLatestFrom in the rxjs docs here: https://www.learnrxjs.io/operators/combination/withlatestfrom.html

Upvotes: 1

Related Questions