diff --git a/modules/@angular/common/src/forms.ts b/modules/@angular/common/src/forms.ts
index 7acbbe1e5a..3e30cd0bd2 100644
--- a/modules/@angular/common/src/forms.ts
+++ b/modules/@angular/common/src/forms.ts
@@ -22,10 +22,10 @@ export {CheckboxControlValueAccessor} from './forms/directives/checkbox_value_ac
export {ControlContainer} from './forms/directives/control_container';
export {ControlValueAccessor, NG_VALUE_ACCESSOR} from './forms/directives/control_value_accessor';
export {DefaultValueAccessor} from './forms/directives/default_value_accessor';
+export {FormControlName} from './forms/directives/form_control_name';
export {Form} from './forms/directives/form_interface';
export {NgControl} from './forms/directives/ng_control';
export {NgControlGroup} from './forms/directives/ng_control_group';
-export {NgControlName} from './forms/directives/ng_control_name';
export {NgControlStatus} from './forms/directives/ng_control_status';
export {NgForm} from './forms/directives/ng_form';
export {NgModel} from './forms/directives/ng_model';
diff --git a/modules/@angular/common/src/forms/directives.ts b/modules/@angular/common/src/forms/directives.ts
index 0cc0993951..3817784581 100644
--- a/modules/@angular/common/src/forms/directives.ts
+++ b/modules/@angular/common/src/forms/directives.ts
@@ -2,8 +2,8 @@ import {Type} from '@angular/core';
import {CheckboxControlValueAccessor} from './directives/checkbox_value_accessor';
import {DefaultValueAccessor} from './directives/default_value_accessor';
+import {FormControlName} from './directives/form_control_name';
import {NgControlGroup} from './directives/ng_control_group';
-import {NgControlName} from './directives/ng_control_name';
import {NgControlStatus} from './directives/ng_control_status';
import {NgForm} from './directives/ng_form';
import {NgModel} from './directives/ng_model';
@@ -18,9 +18,9 @@ import {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValida
export {CheckboxControlValueAccessor} from './directives/checkbox_value_accessor';
export {ControlValueAccessor} from './directives/control_value_accessor';
export {DefaultValueAccessor} from './directives/default_value_accessor';
+export {FormControlName} from './directives/form_control_name';
export {NgControl} from './directives/ng_control';
export {NgControlGroup} from './directives/ng_control_group';
-export {NgControlName} from './directives/ng_control_name';
export {NgControlStatus} from './directives/ng_control_status';
export {NgForm} from './directives/ng_form';
export {NgModel} from './directives/ng_model';
@@ -52,7 +52,7 @@ export {MaxLengthValidator, MinLengthValidator, PatternValidator, RequiredValida
* @experimental
*/
export const FORM_DIRECTIVES: Type[] = /*@ts2dart_const*/[
- NgControlName, NgControlGroup,
+ NgControlGroup,
NgModel, NgForm,
@@ -64,4 +64,4 @@ export const FORM_DIRECTIVES: Type[] = /*@ts2dart_const*/[
];
export const REACTIVE_FORM_DIRECTIVES: Type[] =
- /*@ts2dart_const*/[FormControlDirective, FormGroupDirective];
\ No newline at end of file
+ /*@ts2dart_const*/[FormControlDirective, FormGroupDirective, FormControlName];
\ No newline at end of file
diff --git a/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts b/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts
index 25120cfd65..6552b3ad3c 100644
--- a/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts
+++ b/modules/@angular/common/src/forms/directives/checkbox_value_accessor.ts
@@ -13,14 +13,14 @@ export const CHECKBOX_VALUE_ACCESSOR: any = /*@ts2dart_const*/ {
*
* ### Example
* ```
- *
+ *
* ```
*
* @experimental
*/
@Directive({
selector:
- 'input[type=checkbox][ngControl],input[type=checkbox][formControl],input[type=checkbox][ngModel]',
+ 'input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]',
host: {'(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()'},
providers: [CHECKBOX_VALUE_ACCESSOR]
})
diff --git a/modules/@angular/common/src/forms/directives/default_value_accessor.ts b/modules/@angular/common/src/forms/directives/default_value_accessor.ts
index f29468417f..0bd476bcbd 100644
--- a/modules/@angular/common/src/forms/directives/default_value_accessor.ts
+++ b/modules/@angular/common/src/forms/directives/default_value_accessor.ts
@@ -13,18 +13,18 @@ export const DEFAULT_VALUE_ACCESSOR: any = /*@ts2dart_const*/
/**
* The default accessor for writing a value and listening to changes that is used by the
- * {@link NgModel}, {@link FormControlDirective}, and {@link NgControlName} directives.
+ * {@link NgModel}, {@link FormControlDirective}, and {@link FormControlName} directives.
*
* ### Example
* ```
- *
+ *
* ```
*
* @experimental
*/
@Directive({
selector:
- 'input:not([type=checkbox])[ngControl],textarea[ngControl],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]',
+ 'input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]',
// TODO: vsavkin replace the above selector with the one below it once
// https://github.com/angular/angular/issues/3011 is implemented
// selector: '[ngControl],[ngModel],[ngFormControl]',
diff --git a/modules/@angular/common/src/forms/directives/ng_control_name.ts b/modules/@angular/common/src/forms/directives/form_control_name.ts
similarity index 67%
rename from modules/@angular/common/src/forms/directives/ng_control_name.ts
rename to modules/@angular/common/src/forms/directives/form_control_name.ts
index 257fc4580b..d84e85b086 100644
--- a/modules/@angular/common/src/forms/directives/ng_control_name.ts
+++ b/modules/@angular/common/src/forms/directives/form_control_name.ts
@@ -1,4 +1,4 @@
-import {Directive, Host, Inject, OnChanges, OnDestroy, Optional, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core';
+import {Directive, Host, Inject, Input, OnChanges, OnDestroy, Optional, Output, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core';
import {EventEmitter, ObservableWrapper} from '../../facade/async';
import {FormControl} from '../model';
@@ -14,7 +14,7 @@ import {AsyncValidatorFn, ValidatorFn} from './validators';
export const controlNameBinding: any =
/*@ts2dart_const*/ /* @ts2dart_Provider */ {
provide: NgControl,
- useExisting: forwardRef(() => NgControlName)
+ useExisting: forwardRef(() => FormControlName)
};
/**
@@ -31,39 +31,50 @@ export const controlNameBinding: any =
* ```
* @Component({
* selector: "login-comp",
- * directives: [FORM_DIRECTIVES],
+ * directives: [REACTIVE_FORM_DIRECTIVES],
* template: `
- *
* `})
* class LoginComp {
- * onLogIn(value): void {
+ * loginCtrl = new Control();
+ * passwordCtrl = new Control();
+ * myForm = new FormGroup({
+ * login: loginCtrl,
+ * password: passwordCtrl
+ * });
+ * onLogIn(): void {
* // value === {login: 'some login', password: 'some password'}
* }
* }
* ```
*
- * We can also use ngModel to bind a domain model to the form.
+ * TODO(kara): Remove ngModel example with reactive paradigm
+ * We can also use ngModel to bind a domain model to the form, if you don't want to provide
+ * individual init values to each control.
*
* ```
* @Component({
* selector: "login-comp",
- * directives: [FORM_DIRECTIVES],
+ * directives: [REACTIVE_FORM_DIRECTIVES],
* template: `
- *
* `})
* class LoginComp {
* credentials: {login:string, password:string};
+ * myForm = new FormGroup({
+ * login: new Control(this.credentials.login),
+ * password: new Control(this.credentials.password)
+ * });
*
* onLogIn(): void {
* // this.credentials.login === "some login"
@@ -74,21 +85,18 @@ export const controlNameBinding: any =
*
* @experimental
*/
-@Directive({
- selector: '[ngControl]',
- providers: [controlNameBinding],
- inputs: ['name: ngControl', 'model: ngModel'],
- outputs: ['update: ngModelChange'],
- exportAs: 'ngForm'
-})
-export class NgControlName extends NgControl implements OnChanges,
- OnDestroy {
+@Directive({selector: '[formControlName]', providers: [controlNameBinding]})
+export class FormControlName extends NgControl implements OnChanges, OnDestroy {
/** @internal */
- update = new EventEmitter();
- model: any;
viewModel: any;
private _added = false;
+ @Input('formControlName') name: string;
+
+ // TODO(kara): Replace ngModel with reactive API
+ @Input('ngModel') model: any;
+ @Output('ngModelChange') update = new EventEmitter();
+
constructor(@Host() @SkipSelf() private _parent: ControlContainer,
@Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
/* Array */ any[],
diff --git a/modules/@angular/common/src/forms/directives/ng_control_group.ts b/modules/@angular/common/src/forms/directives/ng_control_group.ts
index fc6fd81abe..d5e7cb06e1 100644
--- a/modules/@angular/common/src/forms/directives/ng_control_group.ts
+++ b/modules/@angular/common/src/forms/directives/ng_control_group.ts
@@ -28,15 +28,15 @@ export const controlGroupProvider: any =
*
diff --git a/modules/@angular/common/src/forms/directives/ng_control_status.ts b/modules/@angular/common/src/forms/directives/ng_control_status.ts
index 01f750efb9..38627e246c 100644
--- a/modules/@angular/common/src/forms/directives/ng_control_status.ts
+++ b/modules/@angular/common/src/forms/directives/ng_control_status.ts
@@ -12,7 +12,7 @@ import {NgControl} from './ng_control';
* @experimental
*/
@Directive({
- selector: '[ngControl],[ngModel],[formControl]',
+ selector: '[formControlName],[ngModel],[formControl]',
host: {
'[class.ng-untouched]': 'ngClassUntouched',
'[class.ng-touched]': 'ngClassTouched',
diff --git a/modules/@angular/common/src/forms/directives/ng_form.ts b/modules/@angular/common/src/forms/directives/ng_form.ts
index 7fdfcea692..ad2a7cc65a 100644
--- a/modules/@angular/common/src/forms/directives/ng_form.ts
+++ b/modules/@angular/common/src/forms/directives/ng_form.ts
@@ -35,8 +35,6 @@ export const formDirectiveProvider: any =
*
* The `ngSubmit` event signals when the user triggers a form submission.
*
- * ### Example ([live demo](http://plnkr.co/edit/ltdgYj4P0iY64AR71EpL?p=preview))
- *
* ```typescript
* @Component({
* selector: 'my-app',
@@ -47,13 +45,13 @@ export const formDirectiveProvider: any =
* `
diff --git a/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts b/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts
index cc6c7b8332..0ff036f5c9 100644
--- a/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts
+++ b/modules/@angular/common/src/forms/directives/select_control_value_accessor.ts
@@ -33,7 +33,7 @@ function _extractId(valueString: string): string {
*/
@Directive({
selector:
- 'select:not([multiple])[ngControl],select:not([multiple])[formControl],select:not([multiple])[ngModel]',
+ 'select:not([multiple])[formControlName],select:not([multiple])[formControl],select:not([multiple])[ngModel]',
host: {'(change)': 'onChange($event.target.value)', '(blur)': 'onTouched()'},
providers: [SELECT_VALUE_ACCESSOR]
})
@@ -87,7 +87,7 @@ export class SelectControlValueAccessor implements ControlValueAccessor {
* ### Example
*
* ```
- *