用于单选按钮的 Angular2 Reactive Forms formControl [英] Angular2 Reactive Forms formControl for radio buttons

查看:25
本文介绍了用于单选按钮的 Angular2 Reactive Forms formControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用响应式表单在 Angular 中构建表单.我正在使用 FormBuilder 制作一组字段.对于文本框,这非常有效.但是我找不到用于单选按钮的 formControl.

I'm building a form in Angular with Reactive Forms. I'm using the FormBuilder to make a group of fields. For textboxes this works extremely well. But I can't find a formControl for radio buttons.

这是如何工作的?我应该像使用文本输入一样使用 <input formControlName="gender" type="radio"> 吗?

How does this work? Should I use <input formControlName="gender" type="radio"> just like I use with text input's?

推荐答案

我应该像处理文本输入那样做 吗?

是的.

这是如何工作的?

表单控件指令使用 ControlValueAccessor 指令与本机元素进行通信.每个可能的输入都有不同类型的 ControlValueAccessors.正确的由值访问器指令的 selector 选择.选择器基于 是什么 type.当您有 type="radio" 时,将使用无线电的值访问器.

Form control directives use a ControlValueAccessor directive to communicate with the native element. There are different types of ControlValueAccessors for each of the possible inputs. The correct one is chosen by the selector of the value accessor directive. The selectors are based on what type the <input> is. When you have type="radio", then the value accessor for radios will be used.

这篇关于用于单选按钮的 Angular2 Reactive Forms formControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆