NgFormControl

export directive NgFormControl

exported from angular2/common defined in angular2/src/common/forms/directives/ng_form_control.ts (line 28)

Binds an existing Control to a DOM element.

Example (live demo)

In this example, we bind the control to an input element. When the value of the input element changes, the value of the control will reflect that change. Likewise, if the value of the control changes, the input element reflects that change.

@Component({ selector: 'my-app', template: ` <div> <h2>NgFormControl Example</h2> <form> <p>Element with existing control: <input type="text" [ngFormControl]="loginControl"></p> <p>Value of existing control: {{loginControl.value}}</p> </form> </div> `, directives: [CORE_DIRECTIVES, FORM_DIRECTIVES] }) export class App { loginControl: Control = new Control(''); }

###ngModel

We can also use ngModel to bind a domain model to the form.

Example (live demo)

@Component({ selector: "login-comp", directives: [FORM_DIRECTIVES], template: "<input type='text' [ngFormControl]='loginControl' [(ngModel)]='login'>" }) class LoginComp { loginControl: Control = new Control(''); login:string; }

Selectors

[ngFormControl]

Inputs

ng-form-control bound to NgFormControl.form

ng-model bound to NgFormControl.model

Outputs

ng-model-change bound to NgFormControl.update

Exported As

ngForm

Constructor

constructor(_validators:
                /* Array<Validator|Function> */ any[], _asyncValidators:
                /* Array<Validator|Function> */ any[], valueAccessors: ControlValueAccessor[])

Not Yet Documented

Members

form : Control

Not Yet Documented

update : EventEmitter

Not Yet Documented

model : any

Not Yet Documented

viewModel : any

Not Yet Documented

ngOnChanges(changes: {[key: string]: SimpleChange}) : void

Not Yet Documented

path : string[]

Not Yet Documented

validator : Function

Not Yet Documented

asyncValidator : Function

Not Yet Documented

control : Control

Not Yet Documented

viewToModelUpdate(newValue: any) : void

Not Yet Documented