Skip to content

Instantly share code, notes, and snippets.

@sanusart
Last active January 12, 2018 19:06
Show Gist options
  • Save sanusart/87500709f91ed020ed15d83c1b5cf66a to your computer and use it in GitHub Desktop.
Save sanusart/87500709f91ed020ed15d83c1b5cf66a to your computer and use it in GitHub Desktop.
Angular sortBy pipe #tag #angular #angular4 #lodash #fp #pipe #tag1
import { Pipe, PipeTransform } from '@angular/core';
import { sortBy, reverse, flow, identity } from 'lodash/fp';
@Pipe({ name: 'sortBy' })
export class SortByPipe implements PipeTransform {
transform(list, field, direction = 'DESC') {
return flow([
sortBy([field]),
direction === 'DESC' ? reverse : identity
])(list);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment