且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用于单选按钮的 Angular2 Reactive Forms formControl

更新时间:2023-12-02 23:53:10

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

是的.

这是如何工作的?

表单控件指令使用 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.