填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

RadioControlValueAccessor

ControlValueAccessor 用于写入单选控件的值和监听单选控件值的更改。这个值访问器由 FormControlDirectiveFormControlNameNgModel 指令使用。

The ControlValueAccessor for writing radio control values and listening to radio control changes. The value accessor is used by the FormControlDirective, FormControlName, and NgModel directives.

Exported from

选择器

属性

属性说明
@Input()
name: string

跟踪单选 input 元素的名称。

Tracks the name of the radio input element.

@Input()
formControlName: string

跟踪绑定到指令的 FormControl 的名称。该名称对应于父 FormGroupFormArray

Tracks the name of the FormControl bound to the directive. The name corresponds to a key in the parent FormGroup or FormArray.

@Input()
value: any

跟踪单选 input 元素的值

Tracks the value of the radio input element

说明

将单选按钮与响应式表单指令一起使用

Using radio buttons with reactive form directives

下面的示例演示了如何在响应式表单中使用单选按钮。当使用响应式表单的单选按钮时,同一组中的单选按钮应具有相同的 formControlName 。所提供的 name 属性是可选的。

The follow example shows how to use radio buttons in a reactive form. When using radio buttons in a reactive form, radio buttons in the same group should have the same formControlName. Providing a name attribute is optional.

      
      import {Component} from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';

@Component({
  selector: 'example-app',
  template: `
    <form [formGroup]="form">
      <input type="radio" formControlName="food" value="beef" > Beef
      <input type="radio" formControlName="food" value="lamb"> Lamb
      <input type="radio" formControlName="food" value="fish"> Fish
    </form>

    <p>Form value: {{ form.value | json }}</p>  <!-- {food: 'lamb' } -->
  `,
})
export class ReactiveRadioButtonComp {
  form = new FormGroup({
    food: new FormControl('lamb'),
  });
}
    

方法

在单选 input 元素上设置 “value”,并取消选中它。

Sets the "value" on the radio input element and unchecks it.

      
      fireUncheck(value: any): void
    
参数
value any
返回值

void