简体   繁体   English

角度4嵌套的反应形式仅在值更改时将输入添加到输入的父级

[英]angular 4 nested reactive form add input on value change to parent of input ONLY

I have a reactive form with nested formarray group. 我有一个带有嵌套formarray组的反应形式。 I have an input that is added on when user type/select **other: ** (there is a space after the colon ( : )) . 当用户键入/选择** other:**(冒号(:)后有一个空格)时,我添加了一个输入。 But the input is showing everywhere not just next to the selected/parent input it shows up next to all the inputS that have the same name. 但是输入不仅仅显示在选定/父输入旁边,还显示在所有具有相同名称的输入旁边。
Here is the code . 这是代码
How can I have the other input field show just next to parent input? 如何在父输入旁边显示另一个输入字段?
在此处输入图片说明

code with CSS 用CSS编码

From what I understood from your question you are trying to change some flags per row, but you write values of those flags to a global variable. 根据您对问题的了解,您正在尝试每行更改一些标志,但是您将这些标志的值写入了全局变量。
What you can do is to pass personRow as parameter to the function which handles the change and then depending on the event type set the flag in the personRow object itself. 您可以做的是将personRow作为参数传递给处理更改的函数,然后根据事件类型在personRow对象本身中设置标志。 That way you can achieve higher level of granularity in control over the behaviour of your form. 这样,您可以在控制表单行为方面获得更高的粒度。

Modified stackblitz can be found here 修改后的stackblitz可以在这里找到

PS please consider separating your component into a set of smaller/reusable ones, it will be easier to manage and easier to modify. PS请考虑将您的组件分成一组较小的/可重复使用的组件,这将更易于管理和修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM