p.location-badge. exported from angular2/forms defined in angular2/src/forms/directives/ng_control_name.ts (line 16) :markdown Creates and binds a control with a specified name to a DOM element. This directive can only be used as a child of NgForm or NgFormModel. # Example In this example, we create the login and password controls. We can work with each control separately: check its validity, get its value, listen to its changes. ``` @Component({selector: "login-comp"}) @View({ directives: [formDirectives], template: `
Login
Login is invalid
Password
`}) class LoginComp { onLogIn(value) { // value === {login: 'some login', password: 'some password'} } } ``` We can also use ng-model to bind a domain model to the form. ``` @Component({selector: "login-comp"}) @View({ directives: [formDirectives], template: `
Login Password
`}) class LoginComp { credentials: {login:string, password:string}; onLogIn() { // this.credentials.login === "some login" // this.credentials.password === "some password" } } ``` .l-main-section h2 Annotations .l-sub-section h3.annotation Directive pre.prettyprint code. @Directive({ selector: '[ng-control]', bindings: [controlNameBinding], properties: ['name: ngControl', 'model: ngModel'], events: ['update: ngModel'], lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange], exportAs: 'form' }) .l-main-section h2 Members .l-sub-section h3 constructor pre.prettyprint code. constructor(parent: ControlContainer, ngValidators: QueryList<NgValidator>) :markdown .l-sub-section h3 update :markdown .l-sub-section h3 model :markdown .l-sub-section h3 viewModel :markdown .l-sub-section h3 ngValidators :markdown .l-sub-section h3 onChange pre.prettyprint code. onChange(c: StringMap<string, any>) :markdown .l-sub-section h3 onDestroy pre.prettyprint code. onDestroy() :markdown .l-sub-section h3 viewToModelUpdate pre.prettyprint code. viewToModelUpdate(newValue: any) :markdown .l-sub-section h3 path :markdown .l-sub-section h3 formDirective :markdown .l-sub-section h3 control :markdown .l-sub-section h3 validator :markdown