Skip to content

Commit f2f3e4a

Browse files
author
Alexey Panashchenko
committed
Add sort Patrons by amount
1 parent 1b30f96 commit f2f3e4a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/app/model/patron.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class Patron {
22
id: Number
33
fullName: string
4-
amount: Number
4+
amount: number
55
email: boolean
66
active: boolean
77
}

src/app/patrons-list/patrons-list.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import {PatronList} from "../model/patron.list";
33
import {PatronService} from "../service/patron.service";
4-
import {Router} from "@angular/router";
54

65
@Component({
76
selector: 'app-patrons-list',
@@ -12,14 +11,21 @@ export class PatronsListComponent implements OnInit {
1211

1312
patronList: PatronList;
1413

15-
constructor(private patronService: PatronService, private router: Router) { }
14+
constructor(private patronService: PatronService) { }
1615

1716
ngOnInit() {
1817
this.patronService.getPatronList().subscribe(data => {
1918
this.patronList = data;
19+
this.sortPatronsByAmount();
2020
});
2121
}
2222

23+
sortPatronsByAmount(): void {
24+
this.patronList.patrons.sort(function(a, b){
25+
return b.amount - a.amount
26+
})
27+
}
28+
2329
transformPrice(val: number): number {
2430
return val/100;
2531
}

0 commit comments

Comments
 (0)