11import { CONST_EXPR } from 'angular2/src/facade/lang' ;
22import { EventEmitter , ObservableWrapper } from 'angular2/src/facade/async' ;
33import { List , StringMapWrapper , StringMap } from 'angular2/src/facade/collection' ;
4- import { Directive , Ancestor , onDestroy , onChange } from 'angular2/angular2' ;
4+
5+ import { Directive , Ancestor , onDestroy , onChange , Query , QueryList } from 'angular2/angular2' ;
56import { forwardRef , Binding , Inject } from 'angular2/di' ;
67
78import { ControlContainer } from './control_container' ;
89import { NgControl } from './ng_control' ;
9- import { controlPath } from './shared' ;
10+ import { NgValidator } from './validators' ;
11+ import { controlPath , composeNgValidator } from './shared' ;
1012import { Control } from '../model' ;
1113
1214const controlNameBinding =
@@ -82,13 +84,17 @@ export class NgControlName extends NgControl {
8284 _parent : ControlContainer ;
8385 ngModel : EventEmitter ;
8486 model : any ;
87+ ngValidators : QueryList < NgValidator > ;
8588 _added : boolean ;
8689
87- constructor ( @Ancestor ( ) _parent : ControlContainer ) {
90+ // Scope the query once https://github.com/angular/angular/issues/2603 is fixed
91+ constructor ( @Ancestor ( ) parent : ControlContainer ,
92+ @Query ( NgValidator ) ngValidators : QueryList < NgValidator > ) {
8893 super ( ) ;
89- this . _parent = _parent ;
94+ this . _parent = parent ;
9095 this . ngModel = new EventEmitter ( ) ;
9196 this . _added = false ;
97+ this . ngValidators = ngValidators ;
9298 }
9399
94100 onChange ( c : StringMap < string , any > ) {
@@ -101,7 +107,6 @@ export class NgControlName extends NgControl {
101107 }
102108 }
103109
104-
105110 onDestroy ( ) { this . formDirective . removeControl ( this ) ; }
106111
107112 viewToModelUpdate ( newValue : any ) : void { ObservableWrapper . callNext ( this . ngModel , newValue ) ; }
@@ -111,4 +116,6 @@ export class NgControlName extends NgControl {
111116 get formDirective ( ) : any { return this . _parent . formDirective ; }
112117
113118 get control ( ) : Control { return this . formDirective . getControl ( this ) ; }
119+
120+ get validator ( ) : Function { return composeNgValidator ( this . ngValidators ) ; }
114121}
0 commit comments