我不知道在我的情況下如何管理我的表格。想象7個(gè)初始值的形式:
- Name
- Company
- Address
- Product (repeatable)
- 序列號(hào)(可重復(fù))
- Return Shipping Instructions
有一個(gè)按鈕,用于創(chuàng)建產(chǎn)品和序列號(hào)輸入字段組件的新實(shí)例(如果有更多產(chǎn)品)。這意味著我需要?jiǎng)?chuàng)建另一個(gè)組件來(lái)創(chuàng)建嵌套表單。我面臨的問(wèn)題是,我不知道如何才能做到這一點(diǎn)。
我當(dāng)前記錄我的值,如下所示:
console.log(this.parentForm.controls.name.value);
console.log(this.parentForm.controls.company.value);
console.log(this.parentForm.controls.email.value);
console.log(this.parentForm.controls.address.value);
console.log(this.parentForm.controls.returnInstructions.value);
但我仍在試圖找出如何存儲(chǔ)我的產(chǎn)品和序列號(hào)值(以及刪除它們的可能性)。我正在考慮將它們存儲(chǔ)在一個(gè)對(duì)象數(shù)組中,該數(shù)組將被發(fā)送到父組件(具有主窗體的組件)。數(shù)組看起來(lái)是這樣的:{Object1:product1,SN1,Object2:product2,SN2...}但是如果發(fā)生這種情況,我不知道如何構(gòu)建它。
這是表單數(shù)組的完美用例。下面的驗(yàn)證只是一個(gè)例子。
然后像這樣移除:
添加如下產(chǎn)品: