X Tutup
Skip to content

Commit ba64b5e

Browse files
committed
fix(forms): scope value accessors, validators, and async validators to self
Closes angular#5440
1 parent 230aad4 commit ba64b5e

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

modules/angular2/src/common/forms/directives/ng_control_group.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
Host,
88
SkipSelf,
99
forwardRef,
10-
Provider
10+
Provider,
11+
Self
1112
} from 'angular2/core';
1213
import {CONST_EXPR} from 'angular2/src/facade/lang';
1314

@@ -80,8 +81,8 @@ export class NgControlGroup extends ControlContainer implements OnInit,
8081
_parent: ControlContainer;
8182

8283
constructor(@Host() @SkipSelf() parent: ControlContainer,
83-
@Optional() @Inject(NG_VALIDATORS) private _validators: any[],
84-
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
84+
@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
85+
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
8586
super();
8687
this._parent = parent;
8788
}

modules/angular2/src/common/forms/directives/ng_control_name.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
SkipSelf,
1313
Provider,
1414
Inject,
15-
Optional
15+
Optional,
16+
Self
1617
} from 'angular2/core';
1718

1819
import {ControlContainer} from './control_container';
@@ -103,11 +104,12 @@ export class NgControlName extends NgControl implements OnChanges,
103104
private _added = false;
104105

105106
constructor(@Host() @SkipSelf() private _parent: ControlContainer,
106-
@Optional() @Inject(NG_VALIDATORS) private _validators:
107+
@Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
107108
/* Array<Validator|Function> */ any[],
108-
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
109+
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
109110
/* Array<Validator|Function> */ any[],
110-
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) {
111+
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
112+
valueAccessors: ControlValueAccessor[]) {
111113
super();
112114
this.valueAccessor = selectValueAccessor(this, valueAccessors);
113115
}

modules/angular2/src/common/forms/directives/ng_form.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'angular2/src/facade/async';
77
import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection';
88
import {isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
9-
import {Directive, forwardRef, Provider, Optional, Inject} from 'angular2/core';
9+
import {Directive, forwardRef, Provider, Optional, Inject, Self} from 'angular2/core';
1010
import {NgControl} from './ng_control';
1111
import {Form} from './form_interface';
1212
import {NgControlGroup} from './ng_control_group';
@@ -90,8 +90,8 @@ export class NgForm extends ControlContainer implements Form {
9090
form: ControlGroup;
9191
ngSubmit = new EventEmitter();
9292

93-
constructor(@Optional() @Inject(NG_VALIDATORS) validators: any[],
94-
@Optional() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
93+
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[],
94+
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
9595
super();
9696
this.form = new ControlGroup({}, null, composeValidators(validators),
9797
composeAsyncValidators(asyncValidators));

modules/angular2/src/common/forms/directives/ng_form_control.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
forwardRef,
1010
Provider,
1111
Inject,
12-
Optional
12+
Optional,
13+
Self
1314
} from 'angular2/core';
1415
import {NgControl} from './ng_control';
1516
import {Control} from '../model';
@@ -86,11 +87,12 @@ export class NgFormControl extends NgControl implements OnChanges {
8687
model: any;
8788
viewModel: any;
8889

89-
constructor(@Optional() @Inject(NG_VALIDATORS) private _validators:
90+
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
9091
/* Array<Validator|Function> */ any[],
91-
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
92+
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
9293
/* Array<Validator|Function> */ any[],
93-
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) {
94+
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
95+
valueAccessors: ControlValueAccessor[]) {
9496
super();
9597
this.valueAccessor = selectValueAccessor(this, valueAccessors);
9698
}

modules/angular2/src/common/forms/directives/ng_form_model.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
forwardRef,
99
Provider,
1010
Inject,
11-
Optional
11+
Optional,
12+
Self
1213
} from 'angular2/core';
1314
import {NgControl} from './ng_control';
1415
import {NgControlGroup} from './ng_control_group';
@@ -107,8 +108,8 @@ export class NgFormModel extends ControlContainer implements Form,
107108
directives: NgControl[] = [];
108109
ngSubmit = new EventEmitter();
109110

110-
constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[],
111-
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
111+
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
112+
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
112113
super();
113114
}
114115

modules/angular2/src/common/forms/directives/ng_model.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
forwardRef,
99
Provider,
1010
Inject,
11-
Optional
11+
Optional,
12+
Self
1213
} from 'angular2/core';
1314
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
1415
import {NgControl} from './ng_control';
@@ -62,9 +63,10 @@ export class NgModel extends NgControl implements OnChanges {
6263
model: any;
6364
viewModel: any;
6465

65-
constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[],
66-
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[],
67-
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) {
66+
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
67+
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[],
68+
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
69+
valueAccessors: ControlValueAccessor[]) {
6870
super();
6971
this.valueAccessor = selectValueAccessor(this, valueAccessors);
7072
}

0 commit comments

Comments
 (0)
X Tutup