Creates and binds a control group to a DOM element.
This directive can only be used as a child of NgForm
or NgFormModel
.
Example:
@Component(
selector: 'my-app',
directives: const [FORM_DIRECTIVES],
template: '''
<div>
<h2>Angular2 Control & ControlGroup Example</h2>
<form #f="ngForm">
<div ngControlGroup="name" #cg-name="form">
<h3>Enter your name:</h3>
<p>First: <input ngControl="first" required></p>
<p>Middle: <input ngControl="middle"></p>
<p>Last: <input ngControl="last" required></p>
</div>
<h3>Name value:</h3>
<pre>{{valueOf(cgName)}}</pre>
<p>Name is {{cgName?.control?.valid ? "valid" : "invalid"}}</p>
<h3>What's your favorite food?</h3>
<p><input ngControl="food"></p>
<h3>Form value</h3>
<pre>{{valueOf(f)}}</pre>
</form>
</div>
'''
})
class App {
String valueOf(NgControlGroup cg) {
if (cg.control == null) {
return null;
}
return JSON.encode(cg.control.value, null, 2);
}
}
This example declares a control group for a user's name. The value and validation state of this group can be accessed separately from the overall form.
- Inheritance
- Object
- AbstractControlDirective<T>
- ControlContainer
- NgControlGroup
- Implements
-
- OnInit
- OnDestroy
- Annotations
- Directive(selector: "[ngControlGroup]", providers: const [controlGroupProvider], inputs: const ["name: ngControlGroup"], exportAs: "ngForm")
Constructors
- NgControlGroup(@ ControlContainer _parent, @ @ @ List _validators, @ @ @ List _asyncValidators)
Properties
- asyncValidator → AsyncValidatorFn
-
read-only
- control → ControlGroup
-
Get the
ControlGroup
backing this binding.read-only - dirty → bool
-
read-only, inherited
- errors → Map<String, dynamic>
-
read-only, inherited
- formDirective → Form
-
Get the
Form
to which this group belongs.read-only - hashCode → int
-
Get a hash code for this object.
read-only, inherited - name → String
-
read / write, inherited
- path → List<String>
-
Get the path to this control group.
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
- validator → ValidatorFn
-
read-only
- value → dynamic
-
read-only, inherited
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
ngOnDestroy(
) → void -
ngOnInit(
) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
toString(
) → String -
Returns a string representation of this object.
inherited