Binds an existing control group to a DOM element.
Example
In this example, we bind the control group to the form element, and we bind the login and password controls to the login and password elements.
@Component(
selector: 'my-app',
template: '''
<div>
<h2>NgFormModel Example</h2>
<form [ngFormModel]="loginForm">
<p>Login: <input type="text" ngControl="login"></p>
<p>Password: <input type="password" ngControl="password"></p>
</form>
<p>Value:</p>
<pre>{{value}}</pre>
</div>
''',
directives: const [FORM_DIRECTIVES]
})
class App {
ControlGroup loginForm;
App() {
loginForm = new ControlGroup({
login: new Control(""),
password: new Control("")
});
}
String get value {
return JSON.encode(loginForm.value);
}
}
We can also use ngModel to bind a domain model to the form.
@Component(
selector: "login-comp",
directives: const [FORM_DIRECTIVES],
template: '''
<form [ngFormModel]='loginForm'>
Login <input type='text' ngControl='login' [(ngModel)]='credentials.login'>
Password <input type='password' ngControl='password'
[(ngModel)]='credentials.password'>
<button (click)="onLogin()">Login</button>
</form>'''
)
class LoginComp {
credentials: {login: string, password: string};
ControlGroup loginForm;
LoginComp() {
loginForm = new ControlGroup({
login: new Control(""),
password: new Control("")
});
}
void onLogin() {
// credentials.login === 'some login'
// credentials.password === 'some password'
}
}
- Inheritance
- Object
- AbstractControlDirective<T>
- ControlContainer
- NgFormModel
- Implements
-
- Form
- OnChanges
- Annotations
Constructors
- NgFormModel(@ @ @ List _validators, @ @ @ List _asyncValidators)
Properties
- control → ControlGroup
-
read-only
- directives → List<NgControl>
-
read / write
- dirty → bool
-
read-only, inherited
- errors → Map<String, dynamic>
-
read-only, inherited
- form → ControlGroup
-
read / write
- formDirective → Form
-
read-only
- hashCode → int
-
Get a hash code for this object.
read-only, inherited - name → String
-
read / write, inherited
- ngBeforeSubmit → dynamic
-
read / write
- ngSubmit → dynamic
-
read / write
- path → List<String>
-
read-only
- pristine → bool
-
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited - touched → bool
-
read-only, inherited
- untouched → bool
-
read-only, inherited
- valid → bool
-
read-only, inherited
- value → dynamic
-
read-only, inherited
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
addControl(
NgControl dir) → void -
Add a control to this form.
-
addControlGroup(
NgControlGroup dir) → void -
Add a group of controls to this form.
-
getControl(
NgControl dir) → Control -
Look up the
Control
associated with a particularNgControl
. -
getControlGroup(
NgControlGroup dir) → ControlGroup -
Look up the
ControlGroup
associated with a particularNgControlGroup
. -
ngOnChanges(
Map<String, SimpleChange> changes) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
onSubmit(
) → bool -
removeControl(
NgControl dir) → void -
Remove a control from this form.
-
removeControlGroup(
NgControlGroup dir) → void -
Remove a group of controls from this form.
-
toString(
) → String -
Returns a string representation of this object.
inherited -
updateModel(
NgControl dir, value) → void -
Update the model for a particular control with a new value.