ngrxngrx-effectsngrx-store-4.0

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


Solution

  • 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