【问题标题】:Angular 4 ngFor pipe not re filter after add an element [duplicate]添加元素后Angular 4 ngFor管道不重新过滤[重复]
【发布时间】:2018-01-13 06:08:11
【问题描述】:

我需要使用数据并首先按价格对它们进行排序,管道工作正常,但是当我添加新元素时,它会将其添加到最后一行并且不再对它们进行排序

<tr *ngFor="let game of gameslist | orderBy: 'amount'" (click)="GameClick(game.id)">...</tr>

我的烟斗

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
  name: 'orderBy'
})
export class OrderByPipe implements PipeTransform {

  transform(array: Array<string>, args: string): Array<string> {
    array.sort((a: any, b: any) => {
      if ( a[args] > b[args] ) {
        return -1;
      }else if ( a[args] < b[args] ) {
        return 1;
      }else {
        return 0;
      }
    });
    return array;
  }
}

添加前

添加后

【问题讨论】:

标签: angular ngfor angular-pipe


【解决方案1】:

通过在管道配置中添加pure: false解决

感谢jmw5598

【讨论】:

    猜你喜欢
    • 2017-11-29
    • 1970-01-01
    • 2023-03-22
    • 2017-03-27
    • 2020-08-24
    • 2018-11-18
    • 2019-12-08
    • 1970-01-01
    相关资源
    最近更新 更多