diff --git a/src/lib/form/base-form.component.ts b/src/lib/form/base-form.component.ts index 72eae14..eefd3ed 100644 --- a/src/lib/form/base-form.component.ts +++ b/src/lib/form/base-form.component.ts @@ -5,7 +5,7 @@ import { AutoUnsubscribe, hasFormChanged } from '../utils'; @Directive() export abstract class BaseFormComponent extends AutoUnsubscribe { form!: FormGroup; - initialFormValue; + initialFormValue!: Record; get changed(): boolean { return hasFormChanged(this.form, this.initialFormValue); diff --git a/src/lib/utils/functions.ts b/src/lib/utils/functions.ts index 4c5b234..6c36967 100644 --- a/src/lib/utils/functions.ts +++ b/src/lib/utils/functions.ts @@ -34,11 +34,11 @@ export function trackByFactory() { return (index: number, item: T): string => item.id; } -export function hasFormChanged(form: FormGroup, initialFormValue): boolean { +export function hasFormChanged(form: FormGroup, initialFormValue: Record): boolean { if (form && initialFormValue) { for (const key of Object.keys(form.getRawValue())) { const initialValue = initialFormValue[key]; - const updatedValue = form.get(key).value; + const updatedValue = form.get(key)?.value; if (initialValue == null && updatedValue != null) { const updatedValueType = typeof updatedValue;