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

FormControlDirective

将独立的 FormControl 实例同步到表单控件元素。

Synchronizes a standalone FormControl instance to a form control element.

查看"说明"...

参见

Exported from

选择器

  • [formControl]

属性

属性说明
@Input('formControl')
form: FormControl

跟踪绑定到本指令的 FormControl 实例。

Tracks the FormControl instance bound to the directive.

@Input('disabled')
isDisabled: boolean
只写

在开发人员模式下触发警告,该输入不应与响应式表单一起使用。

Triggers a warning in dev mode 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.

control: FormControl只读

绑定到此指令的 FormControl

The FormControl bound to this directive.

继承自 NgControl

继承自 AbstractControlDirective

模板变量参考手册

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

说明

请注意,已弃用将 ngModel 输入属性和 ngModelChange 事件与响应式表单指令一起使用的方式,并计划在 Angular 的未来版本中删除。有关详细信息,请参阅已弃用特性

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');
  }
}
    

方法

设置视图模型的新值并发出 ngModelChange 事件。

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

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

视图模型的新值。

The new value for the view model.

返回值

void

继承自 NgControl

继承自 AbstractControlDirective