Chore: Moved from Untyped to Stongly Typed forms.
This commit is contained in:
+8
-6
@@ -1,5 +1,5 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { ProductGroup } from '../../core/product-group';
|
||||
@@ -13,18 +13,20 @@ import { ProductGroupService } from '../product-group.service';
|
||||
})
|
||||
export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
name: FormControl<string | null>;
|
||||
}>;
|
||||
|
||||
item: ProductGroup = new ProductGroup();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: UntypedFormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: ProductGroupService,
|
||||
) {
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string | null>(null),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,7 +67,7 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
getItem(): ProductGroup {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.name = formModel.name!;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user