๐ŸŒ Angular Material Country Autocomplete

February 26, 2026 ยท View on GitHub

A smart, multilingual country search with flags and codes made with Angular
โœจ Enhance your Angular forms with this elegant, high-performance autocomplete โœจ

GitHub Stars Angular Version License: MIT

๐Ÿ“ข Features

  • ๐Ÿ…ฐ๏ธ Fully Compatible with Angular 16-21
    This library is designed to work seamlessly with the latest Angular versions (16, 17, 18, 19, 20, 21).
    It leverages modern Angular features while maintaining backward compatibility.

  • ๐ŸŒ Multi-language Magic
    Supports English, French, Spanish, Italian, German, Arabic, Chinese, Hindi, Bengali, Portuguese, Russian โ€” plus easily extendable to any custom language via provideCountrySelectConfig()

  • ๐ŸŽŒ 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

๐Ÿš€ Demo

Live Demo: https://wlucha.github.io/ng-country-select

Stackblitz: https://stackblitz.com/~/github.com/wlucha/ng-country-select

๐Ÿ› ๏ธ Setup

1. Install Dependencies

Quick Installation (ng add)

ng add @wlucha/ng-country-select

This command will install the @wlucha/ng-country-select library + all required dependencies.

(Alternative) Install Dependencies manually & update Angular.json styles

# 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"
        ]
      }
    }
  }
}    

2. Import Component

import { CountrySelectComponent } from '@wlucha/ng-country-select';

@NgModule({
  imports: [
    CountrySelectComponent,
    // ... other imports
  ]
})

3. Add Basic Usage

<ng-country-select
  [lang]="'en'"
  (countrySelected)="handleSelection($event)"
></ng-country-select>

๐ŸŽ›๏ธ Parameters

๐ŸŽš๏ธ Inputs

ParameterTypeDefaultDescription
defaultCountryCountry | nullnullSets an initial preselected country
formControlFormControl<Country | null>new FormControl(null)Reactive form control for the country select
selectedCountryCountry | null-Sets a country programmatically (after init)
selectedCountryByAlpha2string-Set a country programmatically by its alpha2 code
selectedCountryByAlpha3string-Set a country programmatically by its alpha3 code
selectedCountryByCurrentTranslationstring-Set a country programmatically by its name in the current language
langstring'en'Language for displaying country names โ€” supports built-in and custom languages
searchAllLanguagesbooleanfalseIf true, searching will match in all available translations
placeholderstring'Search country'Placeholder text for the input field
labelstring | undefinedundefinedCustom label for the form field
showLabelbooleantrueWhether to show the label (uses label or placeholder as fallback)
debounceTimenumber100Debounce time in milliseconds for the search input
disabledbooleanfalseDisables the component if true
appearance'fill' | 'outline''fill'Appearance style of the form field
requiredbooleanfalseMarks the field as required if true
requiredErrorMessagestring'A country is required'Error message shown when the field is required and empty
showRequiredErrorMessagebooleanfalseWhether to show the built-in required error message
showCodesbooleanfalseIf true, shows alpha2/alpha3 codes in the autocomplete results
colorThemePalette'primary'Angular Material color palette ('primary', 'accent', 'warn')
includeCountriesstring[][]List of alpha2 country codes to include (e.g., ['us', 'de', 'fr'])
excludeCountriesstring[][]List of alpha2 country codes to exclude (e.g., ['us', 'de', 'fr'])
alpha2OnlybooleanfalseShow only alpha2 codes in the results
alpha3OnlybooleanfalseShow only alpha3 codes in the results
showFlagbooleantrueWhether the flag should be displayed

๐Ÿšจ Outputs

EventTypeDescription
countrySelectedCountryEmits the full country object on selection
inputChangedstringEmits the current search term on change
closedvoidEmits when the autocomplete panel closes

๐Ÿ’ป Power User Setup

<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>

๐ŸŒ Custom Language Support

You can add custom translations or override existing ones using provideCountrySelectConfig().

Adding extra translations (e.g. Polish)

// app.config.ts
import { provideCountrySelectConfig } from '@wlucha/ng-country-select';

export const appConfig: ApplicationConfig = {
  providers: [
    provideCountrySelectConfig({
      extraTranslations: {
        de: { pl: 'Niemcy', ja: 'ใƒ‰ใ‚คใƒ„' },
        at: { pl: 'Austria', ja: 'ใ‚ชใƒผใ‚นใƒˆใƒชใ‚ข' },
        fr: { pl: 'Francja', ja: 'ใƒ•ใƒฉใƒณใ‚น' },
        // ... add translations for all countries
      }
    })
  ]
};

Then use the custom language in your template:

<ng-country-select
  [lang]="'pl'"
  [placeholder]="'Szukaj kraju'"
></ng-country-select>

Replacing the entire country list

For full control, you can replace the built-in country list entirely:

provideCountrySelectConfig({
  countries: [
    {
      alpha2: 'de',
      alpha3: 'deu',
      translations: { en: 'Germany', pl: 'Niemcy', ja: 'ใƒ‰ใ‚คใƒ„' }
    },
    // ... your custom list
  ]
})

Exported symbols

SymbolTypeDescription
provideCountrySelectConfigfunctionProvider helper for app config
COUNTRY_SELECT_CONFIGInjectionTokenToken for advanced DI scenarios
CountrySelectConfiginterfaceConfiguration type

๐ŸŒŸ Support the Project

Love this component? Here's how you can help:

  1. โญ Star the repo (you're awesome!)
  2. ๐Ÿ› Report bugs here
  3. ๐Ÿ’ก Suggest features
  4. ๐Ÿ“ข 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