docs(forms): add radio button examples (#11676)
This commit is contained in:
@ -59,21 +59,33 @@ export class RadioControlRegistry {
|
||||
}
|
||||
|
||||
/**
|
||||
* The accessor for writing a radio control value and listening to changes that is used by the
|
||||
* {@link NgModel}, {@link FormControlDirective}, and {@link FormControlName} directives.
|
||||
* @whatItDoes Writes radio control values and listens to radio control changes.
|
||||
*
|
||||
* ### Example
|
||||
* ```
|
||||
* @Component({
|
||||
* template: `
|
||||
* <input type="radio" name="food" [(ngModel)]="food" value="chicken">
|
||||
* <input type="radio" name="food" [(ngModel)]="food" value="fish">
|
||||
* `
|
||||
* })
|
||||
* class FoodCmp {
|
||||
* food = 'chicken';
|
||||
* }
|
||||
* ```
|
||||
* Used by {@link NgModel}, {@link FormControlDirective}, and {@link FormControlName}
|
||||
* to keep the view synced with the {@link FormControl} model.
|
||||
*
|
||||
* @howToUse
|
||||
*
|
||||
* If you have imported the {@link FormsModule} or the {@link ReactiveFormsModule}, this
|
||||
* value accessor will be active on any radio control that has a form directive. You do
|
||||
* **not** need to add a special selector to activate it.
|
||||
*
|
||||
* ### How to use radio buttons with form directives
|
||||
*
|
||||
* To use radio buttons in a template-driven form, you'll want to ensure that radio buttons
|
||||
* in the same group have the same `name` attribute. Radio buttons with different `name`
|
||||
* attributes do not affect each other.
|
||||
*
|
||||
* {@example forms/ts/radioButtons/radio_button_example.ts region='TemplateDriven'}
|
||||
*
|
||||
* When using radio buttons in a reactive form, radio buttons in the same group should have the
|
||||
* same `formControlName`. You can also add a `name` attribute, but it's optional.
|
||||
*
|
||||
* {@example forms/ts/reactiveRadioButtons/reactive_radio_button_example.ts region='Reactive'}
|
||||
*
|
||||
* * **npm package**: `@angular/forms`
|
||||
*
|
||||
* @stable
|
||||
*/
|
||||
@Directive({
|
||||
selector:
|
||||
|
@ -10,11 +10,8 @@
|
||||
* @module
|
||||
* @description
|
||||
* This module is used for handling user input, by defining and building a {@link FormGroup} that
|
||||
* consists of
|
||||
* {@link FormControl} objects, and mapping them onto the DOM. {@link FormControl} objects can then
|
||||
* be used
|
||||
* to read information
|
||||
* from the form DOM elements.
|
||||
* consists of {@link FormControl} objects, and mapping them onto the DOM. {@link FormControl}
|
||||
* objects can then be used to read information from the form DOM elements.
|
||||
*
|
||||
* Forms providers are not included in default providers; you must import these providers
|
||||
* explicitly.
|
||||
@ -33,6 +30,7 @@ export {NgControlStatus, NgControlStatusGroup} from './directives/ng_control_sta
|
||||
export {NgForm} from './directives/ng_form';
|
||||
export {NgModel} from './directives/ng_model';
|
||||
export {NgModelGroup} from './directives/ng_model_group';
|
||||
export {RadioControlValueAccessor} from './directives/radio_control_value_accessor';
|
||||
export {FormControlDirective} from './directives/reactive_directives/form_control_directive';
|
||||
export {FormControlName} from './directives/reactive_directives/form_control_name';
|
||||
export {FormGroupDirective} from './directives/reactive_directives/form_group_directive';
|
||||
|
Reference in New Issue
Block a user