import { DynamicForm, type FormConfig, type InferFormValue } from '@ng-forge/dynamic-forms';
@Component({
imports: [DynamicForm],
template: `<form [dynamic-form]="config" (submit)="onSubmit($event)"></form>`
})
export class ContactComponent {
config = {
fields: [
{ key: 'title', type: 'text', label: 'Get in Touch', props: { elementType: 'h2' } },
{ key: 'name', type: 'input', label: 'Your Name', required: true },
{ key: 'email', type: 'input', label: 'Email',
required: true, email: true, props: { type: 'email' } },
{ key: 'message', type: 'textarea', label: 'Message',
required: true, minLength: 10, props: { rows: 3 } },
{ key: 'submit', type: 'submit', label: 'Send Message' },
]
} as const satisfies FormConfig;
onSubmit(value: InferFormValue<typeof this.config.fields>) {
// value is fully typed: { name: string, email: string, message: string }
console.log(value);
}
}