FormArray dùng khi số lượng control động, ví dụ nhiều số điện thoại, danh sách địa chỉ, line items trong invoice hoặc survey questions.
Ví dụ thêm phone control động:
typescript
const phones = new FormArray([
new FormControl("", { nonNullable: true }),
])
phones.push(new FormControl("", { nonNullable: true }))Nó giữ collection controls theo index và cho phép push/remove/insert.
- Nếu mỗi item có nhiều field, thường dùng
FormArray<FormGroup<...>>. - Cần cẩn thận validation và
tracktrong template để không làm mất state khi thêm/xóa dòng.