Custom value in Angular Multi select component
26 Aug 20252 minutes to read
The Multi select component allows users to add new options that are not present in the data source when the allowCustomValue
property is enabled. When a user selects a new custom value, the customValueSelection
event is triggered, providing an opportunity to handle the custom input.
The following sample demonstrates configuration of custom value support with the Multi select component.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { MultiSelectModule } from '@syncfusion/ej2-angular-dropdowns'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component } from '@angular/core';
@Component({
imports: [
FormsModule, ReactiveFormsModule, MultiSelectModule, ButtonModule
],
standalone: true,
selector: 'app-root',
// specifies the template string for the MultiSelect component
template: `<ejs-multiselect id='multiselectelement' [dataSource]='sportsData' [fields]='fields' [allowCustomValue]='true' [placeholder]='placeholder'></ejs-multiselect>`
})
export class AppComponent {
constructor() {
}
// defined the array of data
public sportsData: { [key: string]: Object }[] = [
{ id: 'game1', sports: 'Badminton' },
{ id: 'game2', sports: 'Football' },
{ id: 'game3', sports: 'Tennis' }
];
// map the appropriate column
public fields: Object = { text: 'sports', value: 'id' };
// set the placeholder to the MultiSelect input
public placeholder: string = 'Select games';
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));