填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

FormControlDirective

Synchronizes a standalone FormControl instance to a form control element.

查看"说明"...

参见

NgModule

选择器

  • [formControl]

属性

属性说明
viewModel: any

Internal reference to the view model value.

@Input('formControl')
form: FormControl

Tracks the FormControl instance bound to the directive.

@Input('disabled')
isDisabled: boolean
Write-only.

Triggers a warning that this input should not be used with reactive forms.

@Input('ngModel')
model: any
@Output('ngModelChange')
update: EventEmitter
path: string[]只读

Returns an array that represents the path from the top-level form to this control. Each index is the string name of the control on that level.

validator: ValidatorFn | null只读

Synchronous validator function composed of all the synchronous validators registered with this directive.

asyncValidator: AsyncValidatorFn | null只读

Async validator function composed of all the async validators registered with this directive.

control: FormControl只读

The FormControl bound to this directive.

继承自 NgControl

继承自 AbstractControlDirective

模板变量参考手册

标识符用途
ngForm#myTemplateVar="ngForm"

说明

Note that support for using the ngModel input property and ngModelChange event with reactive form directives was deprecated in Angular v6 and is scheduled for removal in a future version of Angular. For details, see Deprecated features.

The following example shows how to register a standalone control and set its value.

import {Component} from '@angular/core'; import {FormControl, Validators} from '@angular/forms'; @Component({ selector: 'example-app', template: ` <input [formControl]="control"> <p>Value: {{ control.value }}</p> <p>Validation status: {{ control.status }}</p> <button (click)="setValue()">Set value</button> `, }) export class SimpleFormControl { control: FormControl = new FormControl('value', Validators.minLength(2)); setValue() { this.control.setValue('new value'); } }
      
      import {Component} from '@angular/core';
import {FormControl, Validators} from '@angular/forms';

@Component({
  selector: 'example-app',
  template: `
     <input [formControl]="control">

     <p>Value: {{ control.value }}</p>
     <p>Validation status: {{ control.status }}</p>

     <button (click)="setValue()">Set value</button>
  `,
})
export class SimpleFormControl {
  control: FormControl = new FormControl('value', Validators.minLength(2));

  setValue() {
    this.control.setValue('new value');
  }
}
    

方法

A lifecycle method called when the directive's inputs change. For internal use only.

ngOnChanges(changes: SimpleChanges): void
      
      ngOnChanges(changes: SimpleChanges): void
    
参数
changes SimpleChanges

A object of key/value pairs for the set of changed inputs.

返回值

void

Sets the new value for the view model and emits an ngModelChange event.

viewToModelUpdate(newValue: any): void
      
      viewToModelUpdate(newValue: any): void
    
参数
newValue any

The new value for the view model.

返回值

void

继承自 NgControl

继承自 AbstractControlDirective