填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写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.