@@ -34,7 +34,7 @@ import * as modelModule from './model';
3434 * login: ["", Validators.required],
3535 * passwordRetry: builder.group({
3636 * password: ["", Validators.required],
37- * passwordConfirmation: ["", Validators.required]
37+ * passwordConfirmation: ["", Validators.required, asyncValidator ]
3838 * })
3939 * });
4040 * }
@@ -58,36 +58,25 @@ export class FormBuilder {
5858 var controls = this . _reduceControls ( controlsConfig ) ;
5959 var optionals = isPresent ( extra ) ? StringMapWrapper . get ( extra , "optionals" ) : null ;
6060 var validator = isPresent ( extra ) ? StringMapWrapper . get ( extra , "validator" ) : null ;
61-
62- if ( isPresent ( validator ) ) {
63- return new modelModule . ControlGroup ( controls , optionals , validator ) ;
64- } else {
65- return new modelModule . ControlGroup ( controls , optionals ) ;
66- }
61+ var asyncValidator = isPresent ( extra ) ? StringMapWrapper . get ( extra , "asyncValidator" ) : null ;
62+ return new modelModule . ControlGroup ( controls , optionals , validator , asyncValidator ) ;
6763 }
68-
6964 /**
70- * Construct a new {@link Control} with the given `value` and `validator `.
65+ * Construct a new {@link Control} with the given `value`,`validator`, and `asyncValidator `.
7166 */
72- control ( value : Object , validator : Function = null ) : modelModule . Control {
73- if ( isPresent ( validator ) ) {
74- return new modelModule . Control ( value , validator ) ;
75- } else {
76- return new modelModule . Control ( value ) ;
77- }
67+ control ( value : Object , validator : Function = null ,
68+ asyncValidator : Function = null ) : modelModule . Control {
69+ return new modelModule . Control ( value , validator , asyncValidator ) ;
7870 }
7971
8072 /**
8173 * Construct an array of {@link Control}s from the given `controlsConfig` array of
82- * configuration, with the given optional `validator`.
74+ * configuration, with the given optional `validator` and `asyncValidator` .
8375 */
84- array ( controlsConfig : any [ ] , validator : Function = null ) : modelModule . ControlArray {
76+ array ( controlsConfig : any [ ] , validator : Function = null ,
77+ asyncValidator : Function = null ) : modelModule . ControlArray {
8578 var controls = controlsConfig . map ( c => this . _createControl ( c ) ) ;
86- if ( isPresent ( validator ) ) {
87- return new modelModule . ControlArray ( controls , validator ) ;
88- } else {
89- return new modelModule . ControlArray ( controls ) ;
90- }
79+ return new modelModule . ControlArray ( controls , validator , asyncValidator ) ;
9180 }
9281
9382 /** @internal */
@@ -109,7 +98,8 @@ export class FormBuilder {
10998 } else if ( isArray ( controlConfig ) ) {
11099 var value = controlConfig [ 0 ] ;
111100 var validator = controlConfig . length > 1 ? controlConfig [ 1 ] : null ;
112- return this . control ( value , validator ) ;
101+ var asyncValidator = controlConfig . length > 2 ? controlConfig [ 2 ] : null ;
102+ return this . control ( value , validator , asyncValidator ) ;
113103
114104 } else {
115105 return this . control ( controlConfig ) ;
0 commit comments