angular-cn/public/docs/js/latest/api/forms/ControlNameDirective-class.jade
2015-06-01 23:18:32 -07:00

112 lines
1.7 KiB
Plaintext

p.location-badge.
exported from <a href='../forms'>angular2/forms</a>
defined in <a href="https://github.com/angular/angular/tree/master/modules/angular2/src/forms/directives/control_name_directive.ts#L11-L65">angular2/src/forms/directives/control_name_directive.ts (line 11)</a>
:markdown
Binds a control to a DOM element.
# Example
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.
Here we use <a href='formDirectives-const.html'><code>formDirectives</code></a>, rather than importing each form directive individually, e.g.
`ControlDirective`, `ControlGroupDirective`. This is just a shorthand for the same end result.
```
@Component({selector: "login-comp"})
@View({
directives: [formDirectives],
template: "<input type='text' [control]='loginControl'>"
})
class LoginComp {
loginControl:Control;
constructor() {
this.loginControl = new Control('');
}
}
```
.l-main-section
h2 Members
.l-sub-section
h3 constructor
pre.prettyprint
code.
constructor(@Ancestor() _parent: ControlContainerDirective)
:markdown
.l-sub-section
h3 formDirective
:markdown
.l-sub-section
h3 onDestroy
pre.prettyprint
code.
onDestroy()
:markdown
.l-sub-section
h3 onInit
pre.prettyprint
code.
onInit()
:markdown
.l-sub-section
h3 path
:markdown