I need to use data and sort them by price first the pipe works fine but when I add new element it add it in the last line and not sort them again
<tr *ngFor="let game of gameslist | orderBy: 'amount'" (click)="GameClick(game.id)">...</tr>
my pipe
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;
}
}