Formularze (Reactive Forms)¶
Wprowadzenie¶
System używa Angular Reactive Forms.
Tworzenie formularza¶
export class BudgetFormComponent {
form = this.fb.group({
name: ['', [Validators.required, Validators.minLength(3)]],
amount: [0, [Validators.required, Validators.min(0)]],
startDate: [new Date(), Validators.required]
});
constructor(private fb: FormBuilder) {}
onSubmit() {
if (this.form.valid) {
const budget = this.form.value;
// Zapisz
}
}
}
Walidacja¶
Custom validators w @msk/validators.