From ba64b5ea5af92a1398746d225aa28a16b39a5eee Mon Sep 17 00:00:00 2001 From: vsavkin Date: Mon, 23 Nov 2015 10:03:56 -0800 Subject: [PATCH] fix(forms): scope value accessors, validators, and async validators to self Closes #5440 --- .../src/common/forms/directives/ng_control_group.ts | 7 ++++--- .../src/common/forms/directives/ng_control_name.ts | 10 ++++++---- .../angular2/src/common/forms/directives/ng_form.ts | 6 +++--- .../src/common/forms/directives/ng_form_control.ts | 10 ++++++---- .../src/common/forms/directives/ng_form_model.ts | 7 ++++--- .../angular2/src/common/forms/directives/ng_model.ts | 10 ++++++---- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/modules/angular2/src/common/forms/directives/ng_control_group.ts b/modules/angular2/src/common/forms/directives/ng_control_group.ts index 63e6eab718556..310b8cd1678d4 100644 --- a/modules/angular2/src/common/forms/directives/ng_control_group.ts +++ b/modules/angular2/src/common/forms/directives/ng_control_group.ts @@ -7,7 +7,8 @@ import { Host, SkipSelf, forwardRef, - Provider + Provider, + Self } from 'angular2/core'; import {CONST_EXPR} from 'angular2/src/facade/lang'; @@ -80,8 +81,8 @@ export class NgControlGroup extends ControlContainer implements OnInit, _parent: ControlContainer; constructor(@Host() @SkipSelf() parent: ControlContainer, - @Optional() @Inject(NG_VALIDATORS) private _validators: any[], - @Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { + @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { super(); this._parent = parent; } diff --git a/modules/angular2/src/common/forms/directives/ng_control_name.ts b/modules/angular2/src/common/forms/directives/ng_control_name.ts index 85ac9b8a7403b..31df287534623 100644 --- a/modules/angular2/src/common/forms/directives/ng_control_name.ts +++ b/modules/angular2/src/common/forms/directives/ng_control_name.ts @@ -12,7 +12,8 @@ import { SkipSelf, Provider, Inject, - Optional + Optional, + Self } from 'angular2/core'; import {ControlContainer} from './control_container'; @@ -103,11 +104,12 @@ export class NgControlName extends NgControl implements OnChanges, private _added = false; constructor(@Host() @SkipSelf() private _parent: ControlContainer, - @Optional() @Inject(NG_VALIDATORS) private _validators: + @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: /* Array */ any[], - @Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: /* Array */ any[], - @Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { + @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) + valueAccessors: ControlValueAccessor[]) { super(); this.valueAccessor = selectValueAccessor(this, valueAccessors); } diff --git a/modules/angular2/src/common/forms/directives/ng_form.ts b/modules/angular2/src/common/forms/directives/ng_form.ts index 0dc8103f7db71..eefa78c328b88 100644 --- a/modules/angular2/src/common/forms/directives/ng_form.ts +++ b/modules/angular2/src/common/forms/directives/ng_form.ts @@ -6,7 +6,7 @@ import { } from 'angular2/src/facade/async'; import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang'; -import {Directive, forwardRef, Provider, Optional, Inject} from 'angular2/core'; +import {Directive, forwardRef, Provider, Optional, Inject, Self} from 'angular2/core'; import {NgControl} from './ng_control'; import {Form} from './form_interface'; import {NgControlGroup} from './ng_control_group'; @@ -90,8 +90,8 @@ export class NgForm extends ControlContainer implements Form { form: ControlGroup; ngSubmit = new EventEmitter(); - constructor(@Optional() @Inject(NG_VALIDATORS) validators: any[], - @Optional() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { + constructor(@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { super(); this.form = new ControlGroup({}, null, composeValidators(validators), composeAsyncValidators(asyncValidators)); diff --git a/modules/angular2/src/common/forms/directives/ng_form_control.ts b/modules/angular2/src/common/forms/directives/ng_form_control.ts index 73bc2000b972b..75f0f6c3d6e8c 100644 --- a/modules/angular2/src/common/forms/directives/ng_form_control.ts +++ b/modules/angular2/src/common/forms/directives/ng_form_control.ts @@ -9,7 +9,8 @@ import { forwardRef, Provider, Inject, - Optional + Optional, + Self } from 'angular2/core'; import {NgControl} from './ng_control'; import {Control} from '../model'; @@ -86,11 +87,12 @@ export class NgFormControl extends NgControl implements OnChanges { model: any; viewModel: any; - constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: + constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: /* Array */ any[], - @Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: /* Array */ any[], - @Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { + @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) + valueAccessors: ControlValueAccessor[]) { super(); this.valueAccessor = selectValueAccessor(this, valueAccessors); } diff --git a/modules/angular2/src/common/forms/directives/ng_form_model.ts b/modules/angular2/src/common/forms/directives/ng_form_model.ts index cef2888eebf77..a766f8a323537 100644 --- a/modules/angular2/src/common/forms/directives/ng_form_model.ts +++ b/modules/angular2/src/common/forms/directives/ng_form_model.ts @@ -8,7 +8,8 @@ import { forwardRef, Provider, Inject, - Optional + Optional, + Self } from 'angular2/core'; import {NgControl} from './ng_control'; import {NgControlGroup} from './ng_control_group'; @@ -107,8 +108,8 @@ export class NgFormModel extends ControlContainer implements Form, directives: NgControl[] = []; ngSubmit = new EventEmitter(); - constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[], - @Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { + constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { super(); } diff --git a/modules/angular2/src/common/forms/directives/ng_model.ts b/modules/angular2/src/common/forms/directives/ng_model.ts index 123f15983241f..6119cc23a4371 100644 --- a/modules/angular2/src/common/forms/directives/ng_model.ts +++ b/modules/angular2/src/common/forms/directives/ng_model.ts @@ -8,7 +8,8 @@ import { forwardRef, Provider, Inject, - Optional + Optional, + Self } from 'angular2/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; import {NgControl} from './ng_control'; @@ -62,9 +63,10 @@ export class NgModel extends NgControl implements OnChanges { model: any; viewModel: any; - constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[], - @Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[], - @Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { + constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[], + @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[], + @Optional() @Self() @Inject(NG_VALUE_ACCESSOR) + valueAccessors: ControlValueAccessor[]) { super(); this.valueAccessor = selectValueAccessor(this, valueAccessors); }