Thi's avatar
HomeAboutNotesBlogTopicsToolsReading
About|My sketches |Cooking |Cafe icon Support Thi
💌 [email protected]

Angular Forms discrete notes

Anh-Thi Dinh
draft
Angular
⚠️
This is a quick & dirty draft, for me only!
No .unshift method for FormArray, no problem
Using FormArray and FormControl without FormGroup in html
Reactive form array (of object) có thể không return value via this.formArr.value mà phải dùng this.formArr.getRawValue() dù cho ko có control nào disabled cả.
❓Chưa hiểu hoàn toàn.
Cái getRawValue() return value của control cụ thể. Ví dụ array of object {name: string, id: number} ← array 4 cái, sửa name của cái index 3 ← cái getRawValue() cho ra giá trị của từng value của control nhỏ nhất, tức formArr.controls.3.controls.name.value. Tất cả các values chỗ khác đều không update giá trị mới nhất!
Nếu chắc chắn trong form ko có control nào disabled thì dùng getRawValue()
About|My sketches |Cooking |Cafe icon Support Thi
💌 [email protected]
1// Add a new control at the end
2formArray.push(new FormControl())
3
4// Add a new control to the beginning
5formArray.insert(0, new FormControl())