Angular2反应形式formControl单选按钮 [英] Angular2 Reactive Forms formControl for radio buttons

查看:193
本文介绍了Angular2反应形式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?

推荐答案

我应该像输入文字一样执行<input formControlName="gender" type="radio">吗?

是的

这是如何工作的?

How does this work?

表单控制指令使用ControlValueAccessor指令与本机元素进行通信.每个可能的输入都有不同类型的ControlValueAccessors.正确的值是由值访问器指令的selector选择的.选择器基于type<input>.当您拥有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反应形式formControl单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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