cleanup(forms): value accessors inject NgControl only from self

This commit is contained in:
vsavkin 2015-07-24 10:22:23 -07:00
parent 469afda53e
commit 45b10a1f0f
3 changed files with 12 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import {Renderer} from 'angular2/render';
import {Directive} from 'angular2/annotations';
import {ElementRef} from 'angular2/core';
import {Self} from 'angular2/di';
import {NgControl} from './ng_control';
import {ControlValueAccessor} from './control_value_accessor';
@ -30,10 +31,12 @@ import {setProperty} from './shared';
}
})
export class CheckboxControlValueAccessor implements ControlValueAccessor {
private cd: NgControl;
onChange = (_) => {};
onTouched = () => {};
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
this.cd = cd;
cd.valueAccessor = this;
}

View File

@ -1,6 +1,7 @@
import {Renderer} from 'angular2/render';
import {Directive} from 'angular2/annotations';
import {ElementRef} from 'angular2/core';
import {Self} from 'angular2/di';
import {NgControl} from './ng_control';
import {ControlValueAccessor} from './control_value_accessor';
import {isBlank, isPresent} from 'angular2/src/facade/lang';
@ -31,10 +32,12 @@ import {setProperty} from './shared';
}
})
export class DefaultValueAccessor implements ControlValueAccessor {
private cd: NgControl;
onChange = (_) => {};
onTouched = () => {};
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
this.cd = cd;
cd.valueAccessor = this;
}

View File

@ -1,5 +1,6 @@
import {Renderer} from 'angular2/render';
import {ElementRef, QueryList} from 'angular2/core';
import {Self} from 'angular2/di';
import {Query, Directive} from 'angular2/annotations';
import {NgControl} from './ng_control';
@ -40,14 +41,15 @@ export class NgSelectOption {
}
})
export class SelectControlValueAccessor implements ControlValueAccessor {
private cd: NgControl;
value: string;
onChange = (_) => {};
onTouched = () => {};
constructor(private cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
@Query(NgSelectOption, {descendants: true}) query: QueryList<NgSelectOption>) {
this.cd = cd;
cd.valueAccessor = this;
this._updateValueWhenListOfOptionsChanges(query);
}