A smart, multilingual country search with flags and codes made with Angular
โจ Enhance your Angular forms with this elegant, high-performance autocomplete โจ
-
๐ ฐ๏ธ Fully Compatible with Angular 16-20
This library is designed to work seamlessly with the latest Angular versions (16, 17, 18, 19, 20).
It leverages modern Angular features while maintaining backward compatibility. -
๐ Multi-language Magic
Supports English, French, Spanish, Italian, German, Arabic, Chinese, Hindi, Bengali, Portuguese and Russian + easily extendable to any language -
๐ Flag Images ๐บ๐ธ ๐ฉ๐ช ๐ซ๐ท ๐ช๐ธ ๐ฎ๐น
OS & Browser independent flag images -
โก Optimized Performance
RxJS-powered search with debounce & virtual scrolling -
๐ Smart Search
Search countries by: โ Localized name โ Any translation โ Alpha2/3 codes -
๐จ Material Design Excellence
Seamless integration with Angular Material components -
๐งฉ Standalone Component
Zero boilerplate integration
Live Demo: https://wlucha.github.io/ng-country-select
Stackblitz: https://stackblitz.com/~/github.com/wlucha/ng-country-select
| Angular Version | โ Supported |
|---|---|
| โ Yes | |
| โ Yes | |
| โ Yes | |
| โ Yes | |
| โ Yes |
ng add @wlucha/ng-country-selectThis command will install the @wlucha/ng-country-select library + all required dependencies.
# Install dependencies
npm install --save @angular/material @angular/cdk @angular/animations flag-icons @wlucha/ng-country-select
# Add the flag icon styles to Angular.json "styles" array
"architect": {
"build": {
"options": {
...,
"styles": [
...,
"flag-icons/css/flag-icons.min.css"
]
}
}
}
} import { CountrySelectComponent } from '@wlucha/ng-country-select';
@NgModule({
imports: [
CountrySelectComponent,
// ... other imports
]
})<ng-country-select
[lang]="'en'"
(countrySelected)="handleSelection($event)"
></ng-country-select>| Parameter | Type | Default | Description |
|---|---|---|---|
defaultCountry |
Country | null |
null |
Sets an initial preselected country |
formControl |
FormControl<Country | null> |
null |
Sets an initial preselected country (FormControl) |
selectedCountry |
Country | null |
- | Sets a country programmatically (after init) |
selectedCountryByAlpha2 |
string |
- | Set a country programmatically by its alpha2 code |
selectedCountryByAlpha3 |
string |
- | Set a country programmatically by its alpha3 code |
selectedCountryByCurrentTranslation |
- | Set a country programmatically by its name in the current language | |
lang |
string |
'en' |
Language for displaying country names (e.g., en, de, fr, es, it) |
searchAllLanguages |
boolean |
false |
If true, searching will match in all available translations |
placeholder |
string |
'Search country' |
Placeholder text for the input field |
debounceTime |
number |
100 |
Debounce time in milliseconds for the search input |
disabled |
boolean |
false |
Disables the component if true |
appearance |
'fill' | 'outline' |
'fill' |
Appearance style of the form field |
required |
boolean |
false |
Marks the field as required if true |
requiredErrorMessage |
boolean |
A country is required |
The error message to show when the field does not have a value and is required |
showRequiredErrorMessage |
boolean |
false |
Whether to show an error message when the field does not have a value and is required |
showCodes |
boolean |
false |
If true, shows alpha2/alpha3 codes in the autocomplete results |
color |
ThemePalette |
'primary' |
Angular Material color palette to use ('primary', 'accent', 'warn') |
includeCountries |
string[] |
[] |
List of country codes to include in the dropdown (e.g., ['US', 'DE', 'FR']) |
excludeCountries |
string[] |
[] |
List of country codes to exclude from the dropdown (e.g., ['US', 'DE', 'FR']) |
alpha2Only |
boolean |
false |
Show only alpha2 codes in the results |
alpha3Only |
boolean |
false |
Show only alpha3 codes in the results |
showFlag |
boolean |
true |
Whether the flag should be displayed |
| Event | Output | Description |
|---|---|---|
countrySelected |
Country |
Full country object on selection |
inputChanged |
string |
Live search term updates |
closed |
void |
When dropdown closes |
<ng-country-select
[lang]="'en'"
[formControl]="countryControl"
[searchAllLanguages]="true"
[showCodes]="true"
[debounceTime]="200"
[required]="true"
[requiredErrorMessage]="'A country is required'"
[showRequiredErrorMessage]="true"
[disabled]="false"
[appearance]="'outline'"
[placeholder]="'Search country'"
[color]="primary"
[alpha2Only]="false"
[alpha3Only]="false"
[showFlag]="true"
[excludeCountries]="['US', 'DE', 'FR']"
(countrySelected)="onCountrySelect($event)"
(inputChanged)="trackSearchTerm($event)"
></ng-country-select>Love this component? Here's how you can help:
- โญ Star the repo (you're awesome!)
- ๐ Report bugs here
- ๐ก Suggest features
- ๐ข Share with your network
# Your star fuels development! โญ
# Clone and explore:
git clone https://github.com/wlucha/ng-country-select.git๐ License: MIT
๐จ๐ป Maintainer: Wilfried Lucha
Made with โค๏ธ & โ by Open Source Contributors
- more languages
- custom option template
- semantic release
