我在我的 Angular 项目中使用 NgRx。我想从我的 ProductsComponent
访问存储在我的商店中的产品。
ProductsComponent.ts
...
import { select, Store } from '@ngrx/store';
...
constructor(private store: Store<any>) {}
我想知道两者之间有什么区别:
public products = this.store.select(selectProducts);
和
public products = this.store.pipe(select(selectProducts));
我应该使用哪一个。
最佳答案
两种选择方法的行为相同并且具有相同的功能。 不同的是,一个是 store 上的方法,一个是 RxJS 管道。
NgRx 团队提倡使用 store.select
,因为它使用起来更友好(您不必导入操作符)。甚至还有一个 eslint 规则 select-style鼓励使用 store.select
.
关于Angular - NgRx - .select(...) 和 .pipe(select...) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68919792/