Sorting a reactive form | بلاگ

Sorting a reactive form

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

I have successfully built a reactive form but I wish to order the results using a custom pipe:


                        
                        
                        
                        
                        
    

And my custom pipe looks like this:

import { Pipe } from "@angular/core";

@Pipe({
    name: "sort"
})
export class ArraySortPipe {
    transform(array: Array, args: string): Array {
        if (array !== undefined) {
            console.log(array);
            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;
    }
}

But this doesn't seem to work. I'm aware that reactive forms array structure are different to that of a basic array since it has a nested "controls" array. Any ideas how I can go about this?

asked 40 secs ago
Andrew Junior Howard

...
نویسنده : استخدام کار بازدید : 7 تاريخ : دوشنبه 23 بهمن 1396 ساعت: 20:08