Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何过滤ngrx中的实体?_Angular_Ngrx - Fatal编程技术网

Angular 如何过滤ngrx中的实体?

Angular 如何过滤ngrx中的实体?,angular,ngrx,Angular,Ngrx,我创建了一个ngrx实体服务: @Injectable({ providedIn: 'root' }) export class ProductsDataService extends EntityCollectionServiceBase<{ id, name, isActive }> { actives$ = this.entities$.pipe(filter(e => e.isActive); <------ but e is an Array! @Inje

我创建了一个ngrx实体服务:

@Injectable({ providedIn: 'root' })
export class ProductsDataService extends EntityCollectionServiceBase<{ id, name, isActive }> {
  actives$ = this.entities$.pipe(filter(e => e.isActive); <------ but e is an Array!
@Injectable({providedIn:'root'})
导出类ProductsDataService扩展EntityCollectionServiceBase{

actives$=this.entities$.pipe(filter(e=>e.isActive);映射函数是正确的方法:

 this.entities$.pipe(map(e => e.filter(...));
Filter用于过滤数据流,而不是过滤数据本身,即发出通过提供条件的值(参考:learnrxjs.io/learn rxjs/operators/Filter/Filter)。换句话说,决定数据流是否仅在特定条件下工作

一个简单的例子:

x.pipe(filter(num => num === 2)).subscribe(val => console.log(val))

只有当x发出2时才会打印。

我开始使用rxjs时也有同样的困惑。在管道的上下文中,操作符映射和过滤器对流进行操作,而不是对传递到流中的数组进行操作。因此
map
允许您将数组更改为其他数组。因此,您希望使用rxjs
map
来更改将数组转换为另一个数组,并对映射对象调用js
array.filter()
,将数组更改为仅包含流输出活动项的数组。