Chore: Moved from Untyped to Stongly Typed forms.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
@ -19,7 +19,12 @@ import { RecipeListDatasource } from './recipe-list-datasource';
|
||||
export class RecipeListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
|
||||
@ViewChild(MatSort, { static: true }) sort?: MatSort;
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
validFrom: FormControl<Date>;
|
||||
validTill: FormControl<Date>;
|
||||
productGroup: FormControl<ProductGroup | string | null>;
|
||||
}>;
|
||||
|
||||
productGroups: ProductGroup[] = [];
|
||||
validFromFilter: BehaviorSubject<Date | null> = new BehaviorSubject<Date | null>(null);
|
||||
validTillFilter: BehaviorSubject<Date | null> = new BehaviorSubject<Date | null>(null);
|
||||
@ -36,11 +41,11 @@ export class RecipeListComponent implements OnInit {
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'validity', 'salePrice', 'costPrice', 'costPercentage'];
|
||||
|
||||
constructor(private route: ActivatedRoute, private fb: UntypedFormBuilder) {
|
||||
this.form = this.fb.group({
|
||||
validFrom: '',
|
||||
validTill: '',
|
||||
productGroup: '',
|
||||
constructor(private route: ActivatedRoute) {
|
||||
this.form = new FormGroup({
|
||||
validFrom: new FormControl(new Date(), { nonNullable: true }),
|
||||
validTill: new FormControl(new Date(), { nonNullable: true }),
|
||||
productGroup: new FormControl<ProductGroup | string | null>(null),
|
||||
});
|
||||
}
|
||||
|
||||
@ -72,8 +77,8 @@ export class RecipeListComponent implements OnInit {
|
||||
});
|
||||
this.productGroups = data.productGroups;
|
||||
this.form.setValue({
|
||||
validFrom: vf === null ? '' : moment(vf, 'DD-MMM-YYYY').toDate(),
|
||||
validTill: vt === null ? '' : moment(vt, 'DD-MMM-YYYY').toDate(),
|
||||
validFrom: vf === null ? new Date() : moment(vf, 'DD-MMM-YYYY').toDate(),
|
||||
validTill: vt === null ? new Date() : moment(vt, 'DD-MMM-YYYY').toDate(),
|
||||
productGroup: '',
|
||||
});
|
||||
this.data.next(data.list);
|
||||
|
||||
Reference in New Issue
Block a user