Fix: Discount and payment received were not working
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export class DiscountDataSource extends DataSource<{ name: string; discount: number }> {
|
||||
constructor(private data: { name: string; discount: number }[]) {
|
||||
constructor(private data: Observable<{ name: string; discount: number }[]>) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<{ name: string; discount: number }[]> {
|
||||
return observableOf(this.data);
|
||||
return this.data;
|
||||
}
|
||||
|
||||
disconnect() {}
|
||||
|
||||
@ -26,7 +26,7 @@ import {
|
||||
MatRow,
|
||||
} from '@angular/material/table';
|
||||
import { round } from 'mathjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
|
||||
import { DiscountDataSource } from './discount-datasource';
|
||||
import { DiscountItem } from './discount-item';
|
||||
@ -71,7 +71,8 @@ export class DiscountComponent {
|
||||
>;
|
||||
}>;
|
||||
|
||||
dataSource: DiscountDataSource = new DiscountDataSource([]);
|
||||
public listObservable = new BehaviorSubject<DiscountItem[]>([]);
|
||||
dataSource: DiscountDataSource = new DiscountDataSource(this.listObservable);
|
||||
|
||||
displayedColumns = ['name', 'discount'];
|
||||
|
||||
@ -91,6 +92,7 @@ export class DiscountComponent {
|
||||
|
||||
this.data.subscribe((list: DiscountItem[]) => {
|
||||
this.list = list;
|
||||
console.log(list);
|
||||
this.form.controls.discounts.clear();
|
||||
|
||||
this.list.forEach((x) => {
|
||||
@ -104,7 +106,7 @@ export class DiscountComponent {
|
||||
}),
|
||||
);
|
||||
});
|
||||
this.dataSource = new DiscountDataSource(this.list);
|
||||
this.listObservable.next(this.list);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user