填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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