Not sure if this is better?
filter.html
<div class="custom-control custom-checkbox mt-3 mb-2 pl-4">
<input type="checkbox" class="custom-control-input" id="customCheck1" formControlName="isOverdue">
<label class="custom-control-label" for="customCheck1">Overdue</label>
</div>
<button class="btn btn-secondary" (click)="apply()"Apply filters</button>
filter.html
list.component.ts
public filter(): void {
this.reportListService.query();
}
list.component.ts
filter.component.ts
@Output()
public readonly change = new EventEmitter<void>();
public apply(): void {
this.change.emit();
this.open = false;
}
filter.compnent.ts
service.ts
public readonly filterForm = new FormGroup({
isOverdue: new FormControl(),
});
public query(): void {
this.loadingSource.next(true);
const query = this.createQueryInput();
this.orderReportRes.query(query).then(res => {
this.setList(res);
}).finally(() => {
this.loadingSource.next(false);
});
}
private createQueryInput(): QueryInput {
const query = this.createQueryModel() as QueryInput;
const metaData = this.metadataForm.getRawValue();
query.limit = metaData.limit ? metaData.limit : 20;
query.offset = metaData.offset ? metaData.offset : 0;
return query;
}
private createQueryModel(): QueryInputFilters {
const formData = this.filterForm.getRawValue();
const filters: QueryInputFilters = {};
console.error(formData.isOverdue);
filters.isOverdue = formData.isOverdue ? true : undefined;
Object.keys(filters).forEach(key => filters[key] === undefined ? delete filters[key] : {});
console.log('filters', filters)
return filters;
}
private setList(res: QueryOutput) {
this.listSource.next(res.orders);
}