问题标签 [formarray]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
16277 浏览

angular - 如何以角度 4 推送到 FormArray([ ])

我有一个看起来像这样的反应角度形式。

以下是打字稿文件:

在上面的 FormGroup 中可以看到 FormArrays :
1. repobranchs
2. repocommits
3. repocontributors
4. repolang
5. repo_pr_s
是空的。现在我想在这些嵌套的 FormArrays 中推送一些数组。

例如以下是我要推送到“repocontributors”的数组:

其他人也同样。

我该怎么做..?
需要帮助。
提前致谢。

0 投票
1 回答
4947 浏览

angular - 在表单数组中禁用反应式表单选择表单控件

我试图通过检查反应形式中的条件来禁用选择表单控件,但我无法在我的表单组件中动态地执行此操作。想知道以前有没有人这样做过?

在我的组件中,我将其设置如下

0 投票
1 回答
789 浏览

angular - 将 ngFor 索引绑定到 Formcontrol Id

当组件启动或添加新行时,我正在尝试将ngFor索引绑定到输入。FormControlName

我制作了整个示例,请看一下 id 不会从输入中自动获取值。

https://stackblitz.com/edit/invoice-id

经过大量研究,我找到了一个简单的解决方案trackBy: trackByFn

0 投票
3 回答
74920 浏览

angular - 带有嵌套表单数组的 Angular 反应式表单

我是 Angular 2 的新手,并决定最好的学习方式是阅读 Angular 官方指南。

我浏览了反应式表单指南 https://angular.io/guide/reactive-forms

演示链接:https ://stackblitz.com/angular/jammvmbrpxle

虽然内容总体上相当不错,但我仍然坚持如何实现更复杂的表单。在给定的示例中,每个英雄都有可能拥有许多地址。地址本身是一个平面对象。

如果 Addresses 有其他信息,例如位于该地址的房间的颜色和类型,该怎么办。

所以表单模型看起来像这样......

}

编辑 - 与 ngOnChanges 一起使用的最终代码

hero-detail.component.ts

hero-detail.component.html(嵌套表单数组部分)

0 投票
1 回答
825 浏览

angular - 带有 Angular 5 的 URL-Repeater-Field 和 FormControls 的 FormArray

我需要一个表单中的 url 列表。一个中继场。像这样的东西: 中继器字段

我正在使用我这样初始化的 FormGroup:

一些getter方法:

在 HTML 端,它看起来像这样:

这已经显示了正确数量的输入(在这个最小示例中为两个)。但是如何将日期绑定到输入?我可以使用什么作为 formControllName?

0 投票
2 回答
1660 浏览

angular - 如何以反应形式获取选定的无线电值

我正在尝试获取单选按钮的 selectedValue 并将其作为 true 与单选文本一起传递。如果选择了选项 1,则 selectedValue 作为 true 发送,否则为 false。如果选择了选项 2,则 selectedValue 将被发送为 true,否则为 false。我无法将其设置为 true。想知道以前有没有人这样做过?

https://stackblitz.com/edit/angular-xfrezb

0 投票
1 回答
7865 浏览

angular-reactive-forms - 如何以反应形式获取下拉列表的选定值

我正在尝试获取要在响应式表单提交时发送的更改事件下拉列表的选定值。我有一个非常相似的场景适用于无线电,基于如何以反应形式获取选定无线电值的答案

这是下拉菜单的代码

在从下拉列表中更改所选选项时,我无法将答案作为 formcontrol 传递给 updateSelection。任何帮助是极大的赞赏。

https://stackblitz.com/edit/angular-acdcac

0 投票
2 回答
6298 浏览

angular - FormArray 与 Angular 5 的 Reactive Form 中的嵌套控件组

我一直在尝试使用响应式方法在 Angular 中创建一个表单。一切似乎都还好,直到我需要使用嵌套在 FormGroup 中的 FormArray。这个想法是得到一个看起来像下面的对象的输出,并且能够将尽可能多的项目传递给 items 数组。


所以基本上所有的表格都可以正常工作,直到项目部分除外。我收到此错误消息

我必须以某种方式使每个项目的控件名称与数组内的索引保持一致(我猜),但我尝试了不同的方法但没有成功。你能建议吗?提前致谢!!


这是我的 TS 文件(我还没有创建一个将更多项目传递给数组的方法):

这是我的html:

0 投票
4 回答
12516 浏览

angular - Angular 材质表内的 FormArray

注意:我成功地在经典 HTML 表中执行 FormArray,如下所示。我想在 Angular Material 表中有一个 FormArray 并用数据填充它。我尝试了与经典 HTML 表相同的方法,但由于错误“找不到带有 id 'name'' 的列” ,我无法编译它

我尝试在我的 Angular Material Table 中有一个 FormArray 这是我的 HTML 文件

这是我的 .TS 文件的一部分

0 投票
2 回答
975 浏览

html - input values does not fill correctly in FormArray

I have trouble with filling the right values into input fields of a FormArray. Here is my html:

So this html is being rendered x times depending on the number of roles i have. This works just fine and no errors are shown.

But here is the Problem: When i remove one Role which is not the last of the Array, the input fields filled with the right roles change. Here are the roles: enter image description here

When i remove role 2 for example, the form looks like this: enter image description here

role2 was being removed correctly, but role3 disappeared and the last two roles have the name of the last role (role8)

Why this happens? When i look to the formArray where all roles are saved, the array has the correct values, here is the evidence:

enter image description here

why the correct values are not shown in the view? Thank you for your help

EDIT: Here is the relevant typescript code: