RadioControlValueAccessor
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.
NgModules
选择器
input[type=radio][formControlName]
input[type=radio][formControl]
input[type=radio][ngModel]
属性
属性 | 说明 |
---|---|
onChange: () => { } | The registered callback function called when a change event occurs on the input element. |
onTouched: () => { } | The registered callback function called when a blur event occurs on the input element. |
@Input() | Tracks the name of the radio input element. |
@Input() | Tracks the name of the |
@Input() | Tracks the value of the radio input element |
说明
Using radio buttons with reactive form directives
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'),
- });
- }
方法
A lifecycle method called when the directive is initialized. For internal use only. |
参数没有参数。 返回值
|
Lifecycle method called before the directive's instance is destroyed. For internal use only. |
参数没有参数。 返回值
|
Sets the "checked" property value on the radio input element. |
Registers a function called when the control value changes. |
Sets the "value" on the radio input element and unchecks it. |
Registers a function called when the control is touched. |
Sets the "disabled" property on the input element. |