填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

SelectMultipleControlValueAccessor

ControlValueAccessor 用於寫入多選控制元件值和監聽多選控制元件更改。這個值訪問器由 FormControlDirectiveFormControlNameNgModel 指令使用。

The ControlValueAccessor for writing multi-select control values and listening to multi-select control changes. The value accessor is used by the FormControlDirective, FormControlName, and NgModel directives.

參見

Exported from

選擇器

屬性

屬性說明
@Input()
compareWith: (o1: any, o2: any) => boolean
只寫

追蹤選項的比較演算法,以在檢查更改時追蹤其標識。

Tracks the option comparison algorithm for tracking identities when checking for changes.

說明

使用多選控制元件

Using a multi-select control

下面的示例向你示範瞭如何將多選控制元件與響應式表單一起使用。

The follow example shows you how to use a multi-select control with a reactive form.

      
      const countryControl = new FormControl();
    
      
      <select multiple name="countries" [formControl]="countryControl">
  <option *ngFor="let country of countries" [ngValue]="country">
    {{ country.name }}
  </option>
</select>
    

自訂選項選取方式

Customizing option selection

要自訂預設的選項比較演算法,可以用 <select> 支援的輸入屬性 compareWith。有關用法,請參見 SelectControlValueAccessor

To customize the default option comparison algorithm, <select> supports compareWith input. See the SelectControlValueAccessor for usage.