app/@overflow/commons/ui/pipe/array-sort.ts
2018-09-13 14:47:22 +09:00

18 lines
393 B
TypeScript

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'sort' })
export class Sort implements PipeTransform {
transform(array: any[], field: string): any[] {
array.sort((a: any, b: any) => {
if (a[field] < b[field]) {
return -1;
} else if (a[field] > b[field]) {
return 1;
} else {
return 0;
}
});
return array;
}
}