SelectMultipleControlValueAccessor
本 ControlValueAccessor 用于写入多选控件值和监听多选控件更改。这个值访问器由 FormControlDirective、FormControlName 和 NgModel 指令使用。
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
选择器
select[multiple][formControlName]select[multiple][formControl]select[multiple][ngModel]
属性
| 属性 | 说明 |
|---|---|
@Input() | 只写 跟踪选项的比较算法,以在检查更改时跟踪其标识。 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.