0
votes

The following code doesn't subscribe:

this.store
      .select(petSelectors.selectPetData)
      .pipe(find(x => x.petName === petName)).subscribe(x => console.log(x));

But if I do this, it does subscribe:

this.store.select(petSelectors.selectPetData).subscribe(x => console.log(x));

UPDATE: this works too

const x = this.store .select(petSelectors.selectPetData).pipe(find(x => x));

but when I add the logic, it doesn't

I'm following the RxJS official documentation: https://rxjs-dev.firebaseapp.com/api/operators/find

I have even to tried inside the pipe(), try with take(1), map(), etc and when I do the .subcribe(), nothing gets printed. I have tried using the async pipe as well.

Object:

{
  "petName": "devpato"
}

The pet name I'm passing is to compare the object with is 'devpato'

1
how's your petSelectors.selectPetData observables looks like? can u give some details about your source observableJameel Moideen
So if you use .pipe(map(x => x)), you dont get the same result as without the pipe?ConnorsFan
@Code-EZ I'm using NgRx to store the state of the pets. Then using a selector to retrive the data that is already an Observable handled by NgrxPatricio Vargas
@ConnorsFan to the rescue!! That actually worked. Idk what I was doing wrong when I was using the .map() but the .find() still not working if i put the logic. this worked const x = this.store .select(petSelectors.selectPetData).pipe(find(x => x));Patricio Vargas
Can you test .pipe(tap(x => console.log(x)).subscribe() ?btx

1 Answers

0
votes

Found my issue! @ConnorsFan basically x => x.petName === petName doesn't work because x is the entire array, not a single object inside of the array. So i need to interate throught x

.pipe(map(x => x.find(u => u.petName ===petName));