menu
menuAPI
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.
class SelectMultipleControlValueAccessor extends BuiltInControlValueAccessor implements ControlValueAccessor { @Input() set compareWith(value: (o1: any, o2: any) => boolean);}
(o1: any, o2: any) => booleanTracks the option comparison algorithm for tracking identities when checking for changes.
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.
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">
@for(country of countries; track $index) {
<option [ngValue]="country">{{ country.name }}</option>
}
</select>
To customize the default option comparison algorithm, <select> supports compareWith input.
See the SelectControlValueAccessor for usage.