Binds an existing 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.

@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: const [CORE_DIRECTIVES, FORM_DIRECTIVES]
)
class App {
  Control loginControl = new Control('');
}

ngModel

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

Example

@Component(
     selector: "login-comp",
     directives: const [FORM_DIRECTIVES],
     template: "<input type='text' [ngFormControl]='loginControl' [(ngModel)]='login'>"
     )
class LoginComp {
 Control loginControl = new Control('');
 String login;
}
Inheritance
Implements
  • OnChanges
Annotations
  • Directive(selector: "[ngFormControl]", providers: const [formControlBinding], inputs: const ["form: ngFormControl", "model: ngModel"], outputs: const ["update: ngModelChange"], exportAs: "ngForm")

Constructors

NgFormControl(@ @ @ List _validators, @ @ @ List _asyncValidators, @ @ @ List<ControlValueAccessor> valueAccessors)

Properties

asyncValidator → AsyncValidatorFn

read-only
control Control

read-only
dirty → bool

read-only, inherited
errors → Map<String, dynamic>

read-only, inherited
form Control

read / write
hashCode → int

Get a hash code for this object.

read-only, inherited
model → dynamic

read / write
name → String

read / write, inherited
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
update → dynamic

read / write
valid → bool

read-only, inherited
validator ValidatorFn

read-only
value → dynamic

read-only, inherited
valueAccessor ControlValueAccessor

read / write, inherited
viewModel → dynamic

read / write

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

ngOnChanges(Map<String, SimpleChange> changes) → 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
viewToModelUpdate(newValue) → void