Trung BìnhAngular iconAngular

FormArray dùng khi nào?

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à track trong template để không làm mất state khi thêm/xóa dòng.

Xem toàn bộ Angular cùng filter theo level & chủ đề con.

Mở danh sách Angular