Angular Pipe不从嵌套的ngFor返回数组

问题描述 投票:0回答:1

我有纯粹的管道来过滤数据我知道它不推荐但在我的情况下过滤器只会在网页更改大多数情况下在页面加载时发生。这是管子

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
 name: 'sortPipe'
})
export class SortPipePipe implements PipeTransform {
 listArr = []  
  transform(value: any[], args?: string): any[] {
  value.forEach((val, index) => {
    if (val.group.indexOf(args) > -1) {
     console.log(val); // this retuning object and not array
     listArr.push(val); // not allowed
    }
  });
  retune val ; //this is object not array
 });
 return null;
 }
}
angular pipe ngfor
1个回答
0
投票

好吧,因为某些原因得到它打字稿并没有让我在数组中推高价值。以下是有类似问题的人的答案

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
 name: 'listFilter'
})
export class ListFilterPipe implements PipeTransform {
 list = [];
 transform(value: any[], args?: string): any[] {
  this.list = [];
  if ( typeof value !== 'undefined' ) {
   value.forEach(val => {
    if (val.group.indexOf(args) > -1) {
      this.list.push(val);
    }
   });
   return this.list;
  }
 }
}
© www.soinside.com 2019 - 2024. All rights reserved.