多个收音机组以一种角反应形式
我看到了此问题的答案,其中包括模板表格。但是,没有一个以反应性形式的formgroup来解决这种情况。
当我从页面上的一个表单中选择一个广播按钮时,它将取消选择默认的无线电按钮 以完全独立的形式和formgroup。为什么这是这样,我该如何修复? (我故意将所有内容分开,甚至是方法调用)
这是Stackblitz: stackblitz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
收音机按钮按名称分组,在您的示例中,您没有提供任何名称,因此所有广播按钮均按单个无线电组分组。每个广播按钮的添加名称以避免取消选择其他按钮。
A radio buttons are grouped by name, In your example you are not providing any name so all the radio buttons are grouped as a single radio group.Add name to each radio button to avoid deselecting others.
Forked Working Example
在基本HTML中,无线电按钮始终与
name
属性分组,一旦所有无线电按钮都具有相同的name
属性,它们会形成无线电组
。这是我们必须做的事情,请在
@input()
中以> @input()
中的app-radio
component中的组件中的属性,然后将其传递给其模板,当您想将其用作无线电组
时,请传递同一组中的所有无线电按钮相同name
值。这是您的应用程序的分叉示例。
stackblitz
,这是我们必须做的一些小变化,使这项工作。
In the basic HTML, the radio buttons are always grouped with
name
attribute, once all the radio buttons have the samename
attribute they form aRadio Group
.Here's the thing we have to do, take the
name
property as@Input()
in yourapp-radio
component and pass it to its template, when you want to use it asRadio Group
, pass all the radio buttons in same group a samename
value.Here's the forked example of your app with fix.
Stackblitz
And these are the few small changes we had to do, make this work.