feat(forms): formGroupName and formArrayName also accepts a number (#32607)

For consistency, `FormGroupName` and `FormaArrayName` also accepts a
number as input's type like `FormControlName`

Closes https://github.com/angular/angular/issues/32436

PR Close #32607
This commit is contained in:
LASLEDJ 2019-09-10 22:39:47 +02:00 committed by Alex Rickabaugh
parent 3efb060127
commit fee28e20bb
4 changed files with 29 additions and 17 deletions

View File

@ -82,7 +82,9 @@ export class AbstractFormGroupDirective extends ControlContainer implements OnIn
* @description
* The path to this group from the top-level directive.
*/
get path(): string[] { return controlPath(this.name, this._parent); }
get path(): string[] {
return controlPath(this.name == null ? this.name : this.name.toString(), this._parent);
}
/**
* @description

View File

@ -23,7 +23,7 @@ export abstract class ControlContainer extends AbstractControlDirective {
* The name for the control
*/
// TODO(issue/24571): remove '!'.
name !: string;
name !: string | number | null;
/**
* @description

View File

@ -76,9 +76,13 @@ export class FormGroupName extends AbstractFormGroupDirective implements OnInit,
* @description
* Tracks the name of the `FormGroup` bound to the directive. The name corresponds
* to a key in the parent `FormGroup` or `FormArray`.
* Accepts a name as a string or a number.
* The name in the form of a string is useful for individual forms,
* while the numerical form allows for form groups to be bound
* to indices when iterating over groups in a `FormArray`.
*/
// TODO(issue/24571): remove '!'.
@Input('formGroupName') name !: string;
@Input('formGroupName') name !: string | number | null;
constructor(
@Optional() @Host() @SkipSelf() parent: ControlContainer,
@ -142,9 +146,13 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy
* @description
* Tracks the name of the `FormArray` bound to the directive. The name corresponds
* to a key in the parent `FormGroup` or `FormArray`.
* Accepts a name as a string or a number.
* The name in the form of a string is useful for individual forms,
* while the numerical form allows for form arrays to be bound
* to indices when iterating over arrays in a `FormArray`.
*/
// TODO(issue/24571): remove '!'.
@Input('formArrayName') name !: string;
@Input('formArrayName') name !: string | number | null;
constructor(
@Optional() @Host() @SkipSelf() parent: ControlContainer,
@ -196,7 +204,9 @@ export class FormArrayName extends ControlContainer implements OnInit, OnDestroy
* Returns an array that represents the path from the top-level form to this control.
* Each index is the string name of the control on that level.
*/
get path(): string[] { return controlPath(this.name, this._parent); }
get path(): string[] {
return controlPath(this.name == null ? this.name : this.name.toString(), this._parent);
}
/**
* @description

View File

@ -128,7 +128,7 @@ export declare const COMPOSITION_BUFFER_MODE: InjectionToken<boolean>;
export declare abstract class ControlContainer extends AbstractControlDirective {
readonly formDirective: Form | null;
name: string;
name: string | number | null;
readonly path: string[] | null;
}
@ -194,7 +194,7 @@ export declare class FormArrayName extends ControlContainer implements OnInit, O
readonly asyncValidator: AsyncValidatorFn | null;
readonly control: FormArray;
readonly formDirective: FormGroupDirective | null;
name: string;
name: string | number | null;
readonly path: string[];
readonly validator: ValidatorFn | null;
constructor(parent: ControlContainer, validators: any[], asyncValidators: any[]);
@ -322,7 +322,7 @@ export declare class FormGroupDirective extends ControlContainer implements Form
}
export declare class FormGroupName extends AbstractFormGroupDirective implements OnInit, OnDestroy {
name: string;
name: string | number | null;
constructor(parent: ControlContainer, validators: any[], asyncValidators: any[]);
}