fix(forms): fix conflicting getter name (#11081)

This commit is contained in:
Kara
2016-08-25 14:56:31 -07:00
committed by Victor Berchet
parent cbe0976426
commit ce08982f78
5 changed files with 20 additions and 8 deletions

View File

@ -65,7 +65,7 @@ export class NgModel extends NgControl implements OnChanges,
viewModel: any; viewModel: any;
@Input() name: string; @Input() name: string;
@Input() disabled: boolean; @Input('disabled') isDisabled: boolean;
@Input('ngModel') model: any; @Input('ngModel') model: any;
@Input('ngModelOptions') options: {name?: string, standalone?: boolean}; @Input('ngModelOptions') options: {name?: string, standalone?: boolean};
@ -83,7 +83,7 @@ export class NgModel extends NgControl implements OnChanges,
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
this._checkForErrors(); this._checkForErrors();
if (!this._registered) this._setUpControl(); if (!this._registered) this._setUpControl();
if ('disabled' in changes) { if ('isDisabled' in changes) {
this._updateDisabled(changes); this._updateDisabled(changes);
} }
@ -160,7 +160,7 @@ export class NgModel extends NgControl implements OnChanges,
} }
private _updateDisabled(changes: SimpleChanges) { private _updateDisabled(changes: SimpleChanges) {
const disabledValue = changes['disabled'].currentValue; const disabledValue = changes['isDisabled'].currentValue;
const isDisabled = disabledValue != null && disabledValue != false; const isDisabled = disabledValue != null && disabledValue != false;
resolvedPromise.then(() => { resolvedPromise.then(() => {

View File

@ -82,7 +82,7 @@ export class FormControlDirective extends NgControl implements OnChanges {
@Output('ngModelChange') update = new EventEmitter(); @Output('ngModelChange') update = new EventEmitter();
@Input('disabled') @Input('disabled')
set disabled(isDisabled: boolean) { ReactiveErrors.disabledAttrWarning(); } set isDisabled(isDisabled: boolean) { ReactiveErrors.disabledAttrWarning(); }
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
/* Array<Validator|Function> */ any[], /* Array<Validator|Function> */ any[],

View File

@ -106,7 +106,7 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
@Input('ngModel') model: any; @Input('ngModel') model: any;
@Output('ngModelChange') update = new EventEmitter(); @Output('ngModelChange') update = new EventEmitter();
@Input('disabled') @Input('disabled')
set disabled(isDisabled: boolean) { ReactiveErrors.disabledAttrWarning(); } set isDisabled(isDisabled: boolean) { ReactiveErrors.disabledAttrWarning(); }
constructor( constructor(
@Optional() @Host() @SkipSelf() private _parent: ControlContainer, @Optional() @Host() @SkipSelf() private _parent: ControlContainer,

View File

@ -325,6 +325,8 @@ export function main() {
expect(form.untouched).toBe(formModel.untouched); expect(form.untouched).toBe(formModel.untouched);
expect(form.statusChanges).toBe(formModel.statusChanges); expect(form.statusChanges).toBe(formModel.statusChanges);
expect(form.valueChanges).toBe(formModel.valueChanges); expect(form.valueChanges).toBe(formModel.valueChanges);
expect(form.disabled).toBe(formModel.disabled);
expect(form.enabled).toBe(formModel.enabled);
}); });
describe('addControl & addFormGroup', () => { describe('addControl & addFormGroup', () => {
@ -401,6 +403,8 @@ export function main() {
expect(controlGroupDir.untouched).toBe(formModel.untouched); expect(controlGroupDir.untouched).toBe(formModel.untouched);
expect(controlGroupDir.statusChanges).toBe(formModel.statusChanges); expect(controlGroupDir.statusChanges).toBe(formModel.statusChanges);
expect(controlGroupDir.valueChanges).toBe(formModel.valueChanges); expect(controlGroupDir.valueChanges).toBe(formModel.valueChanges);
expect(controlGroupDir.disabled).toBe(formModel.disabled);
expect(controlGroupDir.enabled).toBe(formModel.enabled);
}); });
}); });
@ -427,6 +431,8 @@ export function main() {
expect(formArrayDir.dirty).toBe(formModel.dirty); expect(formArrayDir.dirty).toBe(formModel.dirty);
expect(formArrayDir.touched).toBe(formModel.touched); expect(formArrayDir.touched).toBe(formModel.touched);
expect(formArrayDir.untouched).toBe(formModel.untouched); expect(formArrayDir.untouched).toBe(formModel.untouched);
expect(formArrayDir.disabled).toBe(formModel.disabled);
expect(formArrayDir.enabled).toBe(formModel.enabled);
}); });
}); });
@ -446,6 +452,8 @@ export function main() {
expect(controlDir.untouched).toBe(control.untouched); expect(controlDir.untouched).toBe(control.untouched);
expect(controlDir.statusChanges).toBe(control.statusChanges); expect(controlDir.statusChanges).toBe(control.statusChanges);
expect(controlDir.valueChanges).toBe(control.valueChanges); expect(controlDir.valueChanges).toBe(control.valueChanges);
expect(controlDir.disabled).toBe(control.disabled);
expect(controlDir.enabled).toBe(control.enabled);
}; };
beforeEach(() => { beforeEach(() => {
@ -499,6 +507,8 @@ export function main() {
expect(ngModel.untouched).toBe(control.untouched); expect(ngModel.untouched).toBe(control.untouched);
expect(ngModel.statusChanges).toBe(control.statusChanges); expect(ngModel.statusChanges).toBe(control.statusChanges);
expect(ngModel.valueChanges).toBe(control.valueChanges); expect(ngModel.valueChanges).toBe(control.valueChanges);
expect(ngModel.disabled).toBe(control.disabled);
expect(ngModel.enabled).toBe(control.enabled);
}); });
it('should throw when no value accessor with named control', () => { it('should throw when no value accessor with named control', () => {
@ -557,6 +567,8 @@ export function main() {
expect(controlNameDir.untouched).toBe(formModel.untouched); expect(controlNameDir.untouched).toBe(formModel.untouched);
expect(controlNameDir.statusChanges).toBe(formModel.statusChanges); expect(controlNameDir.statusChanges).toBe(formModel.statusChanges);
expect(controlNameDir.valueChanges).toBe(formModel.valueChanges); expect(controlNameDir.valueChanges).toBe(formModel.valueChanges);
expect(controlNameDir.disabled).toBe(formModel.disabled);
expect(controlNameDir.enabled).toBe(formModel.enabled);
}); });
}); });
}); });

View File

@ -222,8 +222,8 @@ export declare class FormControl extends AbstractControl {
export declare class FormControlDirective extends NgControl implements OnChanges { export declare class FormControlDirective extends NgControl implements OnChanges {
asyncValidator: AsyncValidatorFn; asyncValidator: AsyncValidatorFn;
control: FormControl; control: FormControl;
disabled: boolean;
form: FormControl; form: FormControl;
isDisabled: boolean;
model: any; model: any;
path: string[]; path: string[];
update: EventEmitter<{}>; update: EventEmitter<{}>;
@ -238,8 +238,8 @@ export declare class FormControlDirective extends NgControl implements OnChanges
export declare class FormControlName extends NgControl implements OnChanges, OnDestroy { export declare class FormControlName extends NgControl implements OnChanges, OnDestroy {
asyncValidator: AsyncValidatorFn; asyncValidator: AsyncValidatorFn;
control: FormControl; control: FormControl;
disabled: boolean;
formDirective: any; formDirective: any;
isDisabled: boolean;
model: any; model: any;
name: string; name: string;
path: string[]; path: string[];
@ -390,8 +390,8 @@ export declare class NgForm extends ControlContainer implements Form {
export declare class NgModel extends NgControl implements OnChanges, OnDestroy { export declare class NgModel extends NgControl implements OnChanges, OnDestroy {
asyncValidator: AsyncValidatorFn; asyncValidator: AsyncValidatorFn;
control: FormControl; control: FormControl;
disabled: boolean;
formDirective: any; formDirective: any;
isDisabled: boolean;
model: any; model: any;
name: string; name: string;
options: { options: {