Skip to content

Commit 45b10a1

Browse files
committed
cleanup(forms): value accessors inject NgControl only from self
1 parent 469afda commit 45b10a1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

modules/angular2/src/forms/directives/checkbox_value_accessor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Renderer} from 'angular2/render';
22
import {Directive} from 'angular2/annotations';
33
import {ElementRef} from 'angular2/core';
4+
import {Self} from 'angular2/di';
45

56
import {NgControl} from './ng_control';
67
import {ControlValueAccessor} from './control_value_accessor';
@@ -30,10 +31,12 @@ import {setProperty} from './shared';
3031
}
3132
})
3233
export class CheckboxControlValueAccessor implements ControlValueAccessor {
34+
private cd: NgControl;
3335
onChange = (_) => {};
3436
onTouched = () => {};
3537

36-
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
38+
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
39+
this.cd = cd;
3740
cd.valueAccessor = this;
3841
}
3942

modules/angular2/src/forms/directives/default_value_accessor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Renderer} from 'angular2/render';
22
import {Directive} from 'angular2/annotations';
33
import {ElementRef} from 'angular2/core';
4+
import {Self} from 'angular2/di';
45
import {NgControl} from './ng_control';
56
import {ControlValueAccessor} from './control_value_accessor';
67
import {isBlank, isPresent} from 'angular2/src/facade/lang';
@@ -31,10 +32,12 @@ import {setProperty} from './shared';
3132
}
3233
})
3334
export class DefaultValueAccessor implements ControlValueAccessor {
35+
private cd: NgControl;
3436
onChange = (_) => {};
3537
onTouched = () => {};
3638

37-
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
39+
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
40+
this.cd = cd;
3841
cd.valueAccessor = this;
3942
}
4043

modules/angular2/src/forms/directives/select_control_value_accessor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Renderer} from 'angular2/render';
22
import {ElementRef, QueryList} from 'angular2/core';
3+
import {Self} from 'angular2/di';
34
import {Query, Directive} from 'angular2/annotations';
45

56
import {NgControl} from './ng_control';
@@ -40,14 +41,15 @@ export class NgSelectOption {
4041
}
4142
})
4243
export class SelectControlValueAccessor implements ControlValueAccessor {
44+
private cd: NgControl;
4345
value: string;
4446
onChange = (_) => {};
4547
onTouched = () => {};
4648

47-
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
49+
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
4850
@Query(NgSelectOption, {descendants: true}) query: QueryList<NgSelectOption>) {
51+
this.cd = cd;
4952
cd.valueAccessor = this;
50-
5153
this._updateValueWhenListOfOptionsChanges(query);
5254
}
5355

0 commit comments

Comments
 (0)