39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
|
import { AircraftResp } from '../../models/aircraft';
|
|
import { ServiceApiGet } from '../../services/service-api-get.service';
|
|
import { ServiceComm } from '../../services/service-comm.service';
|
|
|
|
@Component({
|
|
selector: 'app-list-of-aircrafts',
|
|
templateUrl: './list-of-aircrafts.component.html',
|
|
styleUrls: ['./list-of-aircrafts.component.css']
|
|
})
|
|
export class ListOfAircraftsComponent implements OnInit {
|
|
public displayedColumns: Array<string> = ['id', 'name'];
|
|
public dataSourceTable;
|
|
public resultsLength = 0;
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
|
|
constructor(
|
|
private serviceApi: ServiceApiGet,
|
|
private serviceComm: ServiceComm
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
this.serviceComm.updatedComponentTitle('List of aircrafts');
|
|
this.getListOfAircrafts();
|
|
}
|
|
|
|
getListOfAircrafts() {
|
|
this.serviceApi.getListOfAircrafts().subscribe(data => {
|
|
data.sort((a, b) => (b.name < a.name) ? 1 : -1);
|
|
this.dataSourceTable = new MatTableDataSource<AircraftResp>(data);
|
|
this.dataSourceTable.paginator = this.paginator;
|
|
this.resultsLength = data.length;
|
|
});
|
|
}
|
|
}
|