30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
import { Customer } from '../../core/customer';
|
|
|
|
import { CustomerListDatasource } from './customer-list-datasource';
|
|
|
|
@Component({
|
|
selector: 'app-customer-list',
|
|
templateUrl: './customer-list.component.html',
|
|
styleUrls: ['./customer-list.component.css'],
|
|
})
|
|
export class CustomerListComponent implements OnInit {
|
|
dataSource: CustomerListDatasource = new CustomerListDatasource([]);
|
|
list: Customer[] = [];
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = ['name', 'phone', 'address', 'printInBill', 'discounts'];
|
|
|
|
constructor(private route: ActivatedRoute) {}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { list: Customer[] };
|
|
data.list.forEach((c) => (c.discounts = c.discounts.filter((d) => d.discount !== 0)));
|
|
this.list = data.list;
|
|
});
|
|
this.dataSource = new CustomerListDatasource(this.list);
|
|
}
|
|
}
|