首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >角度管道未从嵌套的ngFor返回数组

角度管道未从嵌套的ngFor返回数组
EN

Stack Overflow用户
提问于 2018-09-03 04:10:00
回答 1查看 200关注 0票数 0

我使用纯管道来过滤数据,我知道不推荐这样做,但在我的情况下,过滤只会在url更改时发生,大多数情况下是在页面加载时。这是烟斗

代码语言:javascript
复制
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;
 }
}
EN

回答 1

Stack Overflow用户

发布于 2018-09-03 06:49:05

好吧,出于某种原因,typescript不让我在数组中推值。以下是对有类似问题的人的答案

代码语言:javascript
复制
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;
  }
 }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52140664

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档