Introduction
In this article, we are going to implement a multi-select dropdown in Angular applications. We will start from scratch to implement a multi-select dropdown.
In this article,
- Create a new angular app
- Install package
- Implement Multi-select dropdown
- Pass default selected value
- Other Settings
- Callback Methods
Create New Angular APP
For creating a new angular application, run the following command in your command prompt or terminal.
ng new <YourProjectName>
After running this command, angular CLI asks you for some settings like Do you want to enforce stricter type checking and stricter bundle budgets in the workspace? , Would you like to add Angular routing? and Which stylesheet format would you like to use? Give answer as per your preferences.
Installing package
Step 1
- For using multi-select dropdown here we use a package ng-multiselect-dropdown.
- Install this package in your project by the following command.
npm i ng-multiselect-dropdown
Step 2
After successfully installing the package now we need to add this module in our app.module file. Add NgMultiSelectDropDownModule.forRoot() in your import array of app module file.

Implement Multi-select dropdown
Step 1
Create an array of items that you want to show in a dropdown in your .ts file. With your array, you have to define a list of settings used in this multi-select dropdown. To create both arrays as shown in the below code.
import { Component } from '@angular/core';
import { IDropdownSettings, } from 'ng-multiselect-dropdown';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
dropdownList = [];
dropdownSettings:IDropdownSettings={};
ngOnInit() {
this.dropdownList = [
{ item_id: 1, item_text: 'Item1' },
{ item_id: 2, item_text: 'Item2' },
{ item_id: 3, item_text: 'Item3' },
{ item_id: 4, item_text: 'Item4' },
{ item_id: 5, item_text: 'Item5' }
];
this.dropdownSettings = {
idField: 'item_id',
textField: 'item_text',
};
}
}
Step 2
Create a dropdown in your component.html file as shown in the below code. Here we pass our item array in data attribute and settings in settings attributes. As you saw in the above code in the setting list we pass the id field and the text field which defines that from our data array we want to use item_id as an ID field and item_text as a text field.
<div style="width:50%">
<ng-multiselect-dropdown
[settings]="dropdownSettings"
[data]="dropdownList">
</ng-multiselect-dropdown>
</div>
Output

Pass default selected value
Step 1
For passing default selection, we need to add this multi-select dropdown in the form. For that first, add FormsModule, ReactiveFormsModule in your import array of the app module files.
Step 2
Create a new form group and select list item array as shown below code.
import { Component } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { IDropdownSettings, } from 'ng-multiselect-dropdown';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
dropdownList = [];
selectedItems=[];
dropdownSettings:IDropdownSettings={};
dropDownForm:FormGroup;
constructor(private fb: FormBuilder) {}
ngOnInit() {
this.dropdownList = [
{ item_id: 1, item_text: 'Item1' },
{ item_id: 2, item_text: 'Item2' },
{ item_id: 3, item_text: 'Item3' },
{ item_id: 4, item_text: 'Item4' },
{ item_id: 5, item_text: 'Item5' }
];
this.dropdownSettings = {
idField: 'item_id',
textField: 'item_text',
};
this.selectedItems = [
{ item_id: 3, item_text: 'Item3' },
{ item_id: 4,item_text: 'Item4' }
];
this.dropDownForm = this.fb.group({
myItems: [this.selectedItems]
});
}
}








peddirajuPosted May 22, 2024, 2:22 PM
I am using showSelectedItemsAtTop: true, to display checked items in top of the binded data , But it is not working for me, Please suggest
ammad khanPosted Feb 22, 2023, 7:51 AM
This control has issue and don't work when put in table row (Tr,Td)
Tiago AraujoPosted Jan 30, 2023, 6:45 PM
Is there any way to clear the textbox when the data list is cleared?
Tiago AraujoPosted Jan 16, 2023, 12:00 PM
How do I select one item and place all the other items as disabled? is that possible? Thanks.
dip sPosted Nov 2, 2022, 6:22 AM
When i try to add code in app.module. it gives error. Is this code works for some specific version of angular? Thank you.
navnath kalhatkarPosted Apr 21, 2022, 1:08 PM
If we select multiple values the selected bar size is increase , how to fix it and will show the selected as "items + 17 more"
Ganesh MorePosted Mar 7, 2022, 10:05 AM
How do we apply custom css like changing back ground color and all
Evan GPosted Dec 28, 2021, 8:27 AM
Nice Control. Is there a way to put it in a disabled state or readonly mode. Init in FormGroup doesn't seem to work.Thanks.