Hai cách build form trong Angular:
| Template-driven | Reactive | |
|---|---|---|
| Khai báo | Trong template (ngModel) | Trong class (FormGroup/FormControl) |
| Form model | Angular tự tạo ngầm | Dev định nghĩa tường minh |
| Validation | Directive trên template | Validator function trong code |
| Async/dynamic | Khó | Dễ (thêm/bớt control runtime) |
| Test | Khó (phụ thuộc DOM) | Dễ (test model trực tiếp) |
typescript
// Reactive
form = new FormGroup({
email: new FormControl("", [Validators.required, Validators.email]),
})Chọn: Template-driven cho form đơn giản; Reactive cho form phức tạp, dynamic, cần test — production thường ưu tiên Reactive.
Lưu ý 2026: Angular đang phát triển Signal Forms (@angular/forms/signals, experimental) quản lý state từ signal model — đáng theo dõi nhưng chưa nên dùng cho form business-critical.