refactor(forms): Remove readonly getters in forms (#19188)
PR Close #19188
This commit is contained in:
@ -82,8 +82,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
|
||||
private _added = false;
|
||||
/** @internal */
|
||||
viewModel: any;
|
||||
/** @internal */
|
||||
_control: FormControl;
|
||||
readonly control: FormControl;
|
||||
|
||||
@Input('formControlName') name: string;
|
||||
|
||||
@ -135,8 +134,6 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
|
||||
return composeAsyncValidators(this._rawAsyncValidators) !;
|
||||
}
|
||||
|
||||
get control(): FormControl { return this._control; }
|
||||
|
||||
private _checkParentType(): void {
|
||||
if (!(this._parent instanceof FormGroupName) &&
|
||||
this._parent instanceof AbstractFormGroupDirective) {
|
||||
@ -150,7 +147,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
|
||||
|
||||
private _setUpControl() {
|
||||
this._checkParentType();
|
||||
this._control = this.formDirective.addControl(this);
|
||||
(this as{control: FormControl}).control = this.formDirective.addControl(this);
|
||||
if (this.control.disabled && this.valueAccessor !.setDisabledState) {
|
||||
this.valueAccessor !.setDisabledState !(true);
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ export const formDirectiveProvider: any = {
|
||||
})
|
||||
export class FormGroupDirective extends ControlContainer implements Form,
|
||||
OnChanges {
|
||||
private _submitted: boolean = false;
|
||||
public readonly submitted: boolean = false;
|
||||
|
||||
private _oldForm: FormGroup;
|
||||
directives: FormControlName[] = [];
|
||||
|
||||
@ -88,8 +89,6 @@ export class FormGroupDirective extends ControlContainer implements Form,
|
||||
}
|
||||
}
|
||||
|
||||
get submitted(): boolean { return this._submitted; }
|
||||
|
||||
get formDirective(): Form { return this; }
|
||||
|
||||
get control(): FormGroup { return this.form; }
|
||||
@ -134,7 +133,7 @@ export class FormGroupDirective extends ControlContainer implements Form,
|
||||
}
|
||||
|
||||
onSubmit($event: Event): boolean {
|
||||
this._submitted = true;
|
||||
(this as{submitted: boolean}).submitted = true;
|
||||
syncPendingControls(this.form, this.directives);
|
||||
this.ngSubmit.emit($event);
|
||||
return false;
|
||||
@ -144,7 +143,7 @@ export class FormGroupDirective extends ControlContainer implements Form,
|
||||
|
||||
resetForm(value: any = undefined): void {
|
||||
this.form.reset(value);
|
||||
this._submitted = false;
|
||||
(this as{submitted: boolean}).submitted = false;
|
||||
}
|
||||
|
||||
|
||||
@ -152,10 +151,10 @@ export class FormGroupDirective extends ControlContainer implements Form,
|
||||
_updateDomValue() {
|
||||
this.directives.forEach(dir => {
|
||||
const newCtrl: any = this.form.get(dir.path);
|
||||
if (dir._control !== newCtrl) {
|
||||
cleanUpControl(dir._control, dir);
|
||||
if (dir.control !== newCtrl) {
|
||||
cleanUpControl(dir.control, dir);
|
||||
if (newCtrl) setUpControl(newCtrl, dir);
|
||||
dir._control = newCtrl;
|
||||
(dir as{control: FormControl}).control = newCtrl;
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user