Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - NgRx - difference between .select(...) and .pipe(select...)

I am using NgRx in my Angular project. I want to access the products that are stored in my store from my ProductsComponent.

ProductsComponent.ts

...
import { select, Store } from '@ngrx/store';
...
constructor(private store: Store<any>) {}

I'm wondering what is the differences between:

public products = this.store.select(selectProducts);

and

public products = this.store.pipe(select(selectProducts));

and which one I should use.

like image 558
Nicolas Bodin-Ripert Avatar asked Apr 26 '26 04:04

Nicolas Bodin-Ripert


1 Answers

Both select methods behave the same and have the same functionality. The difference is that one is a method on the store, while the other is a RxJS pipe.

The NgRx team promotes to use store.select because it's more friendly to use (you don't have to import the operator). There's even a eslint rule select-style that encourages to use store.select.

like image 112
timdeschryver Avatar answered Apr 28 '26 05:04

timdeschryver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!