Why 'subscribe' doesn't trigger when chain pipe with 'select' from NgRx in Angular

226 Views Asked by At

I have two examples of code, and I can't understand why second example is not working. For me they are equivalent.

First example is working:

this.someValue$ = this.store.pipe(
  select(someValue),
  takeUntil(this.ngUnsubscribe$$)
);
this.someValue$.subscribe(someValue => this.someValue= someValue)

And second example is not working when the store has changes, it triggers only once:

this.store.pipe(
  select(someValue),
  takeUntil(this.ngUnsubscribe$$)
).subscribe(someValue => this.someValue= someValue);

So in second example I try to not create the redundant variable 'someValue$' and subscribe to the the store with 'select' inside pipe immediately. But as I mention above it doesn't work when some changes happens in store. In first example it works fine.

Both examples run in OnInit Angular hook.

Thanks!

0

There are 0 best solutions below