45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { MatTable } from '@angular/material/table';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { BehaviorSubject } from 'rxjs';
|
|
|
|
import { Product } from '../../core/product';
|
|
import { SaleCategory } from '../../core/sale-category';
|
|
import { ToasterService } from '../../core/toaster.service';
|
|
import { SaleCategoryService } from '../sale-category.service';
|
|
|
|
import { SaleCategoryListDatasource } from './sale-category-list-datasource';
|
|
|
|
@Component({
|
|
selector: 'app-sale-category-list',
|
|
templateUrl: './sale-category-list.component.html',
|
|
styleUrls: ['./sale-category-list.component.css'],
|
|
})
|
|
export class SaleCategoryListComponent implements OnInit {
|
|
@ViewChild('table', { static: true }) table?: MatTable<SaleCategory>;
|
|
data: BehaviorSubject<SaleCategory[]> = new BehaviorSubject<SaleCategory[]>([]);
|
|
dataSource: SaleCategoryListDatasource = new SaleCategoryListDatasource(this.data);
|
|
list: SaleCategory[] = [];
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = ['name', 'discountLimit', 'tax'];
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private toaster: ToasterService,
|
|
private ser: SaleCategoryService,
|
|
) {
|
|
this.data.subscribe((data: SaleCategory[]) => {
|
|
this.list = data;
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { list: SaleCategory[] };
|
|
this.data.next(data.list);
|
|
});
|
|
this.dataSource = new SaleCategoryListDatasource(this.data);
|
|
}
|
|
}
|