Kątowa 4-kolumna sortująca


Posortowałem kolumny tabeli na podstawie tego przykładu:

Sortowanie kolumn tabeli
https://plnkr.co/edit/nll91Dbc ... eview
To jest potok kodu:
import {Pipe, PipeTransform} from 'angular2/core';@Pipe({ name: 'orderBy' })
export class OrderrByPipe implements PipeTransform { transform(records: Array<any>, args?: any): any { return records.sort(function(a, b){
if(a[args.property] < b[args.property]){
return -1 * args.direction;
}
else if( a[args.property] > b[args.property]){
return 1 * args.direction;
}
else{
return 0;
}
});
};
}

To jest kod HTML:
<tr *ngFor="let particular of particulars | orderBy: {property: column, direction: direction} | slice:1; let i = index">

Importuj w komponencie:
import { OrderrByPipe } from '../pipes/orderby.pipe';

Chcę przenieść rury do Angular 4, jak mogę to zrobić?
Oto błąd w konsoli:
error_handler.js:60 Error: Uncaught (in promise): Error: Error in ./ParticularsListComponent class ParticularsListComponent - inline template:42:14 caused by: Cannot read property 'sort' of undefined
Error: Error in ./ParticularsListComponent class ParticularsListComponent - inline template:42:14 caused by: Cannot read property 'sort' of undefined

Zaproszony:
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Twój problem pochodzi ze zmiennej
specifics
, która nie jest zdefiniowana.
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

import { Pipe, PipeTransform } from '@angular/core';@Pipe({
name: 'orderby'
})
export class OrderbyPipe implements PipeTransform {
//private records : Array<any> = []; transform(records :Array<Object>, args?: any): any {
if(records != null){
return records.sort(function(a, b){
if (a[args.property] === '' || a[args.property] === null || typeof a[args.property] === 'undefined') {
return 1 * args.direction;
}
if (b[args.property] === '' || b[args.property] === null || typeof b[args.property] === 'undefined') {
return -1 * args.direction;
}
if(a[args.property] < b[args.property]){
return -1 * args.direction;
}
else if( a[args.property] > b[args.property]){
return 1 * args.direction;
}
else{
return 0;
}
});
}
};}

Aby odpowiedzieć na pytania, Zaloguj się lub Zarejestruj się