Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ngx-country-selector

evicio1225MIT20.1.0TypeScript support: included

A modern Angular country selector component with flags, search, and Material Design

angular, angular-20, country, selector, dropdown, picker, flags, country-flags, country-picker, country-selector, country-dropdown, angular-material, material-design, autocomplete, search, typescript, component, angular-component, ngx, form-control, reactive-forms, mat-autocomplete, country-codes, iso-codes, localization, i18n, ui-component, frontend

readme

ngx-country-selector

A modern, feature-rich Angular country selector component built with Angular Material. This library provides a beautiful, accessible, and highly customizable dropdown for selecting countries with support for flags, country codes, local names, and more.

✨ Features

  • 🎨 Built with Angular Material - Leverages Material Design components for consistent UI/UX
  • 🏳️ Country Flags - Visual flag representations for all countries
  • 🌍 Comprehensive Country Data - Includes country codes, local names, capitals, currencies, and languages
  • 🔍 Search & Filter - Built-in search functionality with autocomplete
  • Performance Optimized - Supports zoneless change detection for better performance
  • 🎯 Highly Customizable - Extensive configuration options for appearance and behavior
  • Accessible - Full accessibility support with ARIA attributes
  • 📱 Responsive - Works seamlessly across all device sizes
  • 🔧 Angular 20 Ready - Compatible with the latest Angular version

🛠️ Built With

  • Angular 20+ - Modern Angular framework
  • Angular Material 20+ - Material Design components (mat-form-field, mat-autocomplete, mat-input, mat-icon, mat-progress-bar, mat-divider)
  • TypeScript - Type-safe development experience
  • SCSS - Styled with modern CSS preprocessor

Note: Angular CDK is included as a peer dependency of Angular Material but is not directly used by this library.

This library was generated with Angular CLI version 20.3.2.

📋 Prerequisites

This library requires Angular Material to be installed in your project, as it uses Material Design components like mat-form-field, mat-autocomplete, and mat-input.

If you don't have Angular Material installed:

ng add @angular/material

🚀 Getting started

  1. Once your Angular application setup is ready, install the ngx-country-selector library using the following command:
npm i ngx-country-selector
  1. Add the CSS Either import the CSS directly to styles.scss file

    @import  "node_modules/ngx-country-selector/assets/styles.css";

    Or, add CSS file in angular.json in the styles array in the build section

     "styles": [
               "node_modules/ngx-country-selector/assets/styles.css",
               "src/styles.scss"
             ],
  2. Import CountrySelectorLibraryComponent import CountrySelectorLibraryComponent in module where you want to add the countries dropdown, it may be app-module, some lazy loaded module or a standalone component

      imports: [
     CountrySelectorLibraryComponent
     ],
  3. Add the country component to the component where is being used
<lib-country-selector></lib-country-selector>

Properties and their usage

The below table explains what all Input properties country dropdown accepts and their usage

Property Type and default values Description
preferredCountryCodes Type: string array(string[]),Default value: [] the list of country codes which needs to be displayed on top section. ex. if user provided ['in', 'us'], India and United States will be displayed on top
blockedCountryCodes Type: string array(string[]),Default value: [] an array of country codes which are not required in the list. Ex. if some client is not servicing some specific countries can be removed from the country dropdown using this.
allowedCountryCodes Type: string array(string[]),Default value: [] Only countries which will be displayed in the country list
selectedCountryConfig Type: IConfig (see table below for IConfig properties), Default value: {} Provides config for the selected country, and controls what all will be displayed. Ex. if the user do not want to display flag for the selected item, can be controlled with this property(refer to config table for details)
countryListConfig Type: IConfig (see table below for IConfig properties), Default value: {} Provides config for the country list, and controls what all will be displayed in the country list. Ex. if the user do not want to see flag or dial code or name in the country list, can be controlled with this property(refer to config table for details)
label Type: string Default value: 'Select country' `mat-form-field` label's text
placeholderText Type: string Default value: 'Select country' To change the default placeholder label.
loading Type: boolean Default value: false Whether the component is loading.
readonly Type: boolean Default value: false Whether the component is read only.
clearable Type: boolean Default value: false To show clear button.
required Type: boolean Default value: false Whether the component is required. Note: `FormControl` validator need to be setup too
error Type: string Default value: '' To set the error message for required validation.

Events

onCountryChange Country type ICountry returns the selected country

Reactive forms

 loginForm = new FormGroup({
      username: new FormControl('', [Validators.required]),
      password: new FormControl('', Validators.required),
      country: new FormControl({value: {code:'in'} as ICountry | null, disabled: false},
         Validators.required), // need to send both validator and required input value to make it work
    });
  <lib-country-selector
  [allowedCountryCodes]="allowedCountryCode()"
  [countryListConfig]="config"
  [selectedCountryConfig]="selectedConfig"
  [loading]="loading()"
  [readonly]="readonly() || loading()"
  label="Country"
  [clearable]="!shouldCountryLocked()"
  [customNaming]="{ gb: 'United Kingdom'}"
  formControlName="country"
  (onCountryChange)="onCountryChange($event)"
  error="Country is required"
  [required]="true"
  ></lib-country-selector>

IConfig properties and usage

Config properties can be used to control what will be displayed in the country list and for the selected country.

Exported interface

export interface IConfig {
  hideFlag?: boolean;
  hideCode?: boolean;
  hideName?: boolean;
  showLocalName?: boolean;
  hideSearch?: boolean;
  hideDialCode?: boolean;
  displayCapital?: boolean;
  displayLanguageCode?: boolean;
  displayLanguageName?: boolean;
  displayCurrencyCode?: boolean
  displayCurrencyName?: boolean
  displayCurrencySymbol?: boolean

}
hideFlag Boolean, Default value: false to hide flag from country list or selected country
hideCode Boolean, Default value: false to hide country code
hideName Boolean, Default value: false to hide country name
showLocalName Boolean, Default value: false to show local name of the country
hideSearch Boolean, Default value: false to hide search field from country list
hideDialCode Boolean, Default value: false to hide dial code
displayCapital Boolean, Default value: false to display country capital
displayLanguageCode Boolean, Default value: false to display country language code
displayLanguageName Boolean, Default value: false to display country language name
displayCurrencyCode Boolean, Default value: false to display country currency code
displayCurrencyName Boolean, Default value: false to display country currency name
displayCurrencySymbol Boolean, Default value: false to display country currency symbol

Output on country selection

On country selection output of ICountry type will be emitted. Handle country change event

<lib-country-selector (onCountryChange)="onCountryChange($event)"></lib-country-selector>
  onCountryChange(country: ICountry){
    console.log(country);
  }

output in console

{
    name: 'Afghanistan',
    localName: '‫افغانستان‬‎',
    code: 'AF',
    capital: 'Kabul',
    region: 'AS',
    currency: {
      code: 'AFN',
      name: 'Afghan afghani',
      symbol: '؋',
    },
    language: {
      code: 'ps',
      name: 'Pashto',
    },
    dialling_code: '+93',
    isoCode: '004',
  },

exported ICountry interface

export interface ICountry {
  name?: string;
  localName?: string;
  code?: string;
  capital?: string;
  region?: string;
  currency?: ICurrency
  language?: ILanguage
  dialling_code?: string;
  isoCode?: string;
  demonym?: string;
}

export interface ICurrency {
  code?: string | null;
  name?: string;
  symbol?: string | null;
}

export interface ILanguage {
    code?: string;
    name?: string;
    iso639_2?: string,
    nativeName?: string
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgment

This project includes code and concepts inspired by the following:

  1. angular-material-extensions/select-country by Anthony Nahas, licensed under the MIT License.
  2. ngx-countries-dropdown by Kapil Kumar, licensed under the MIT License.

changelog

Changelog

All notable changes to this project will be documented in this file.

[20.1.0] - 2025-10-07

🚀 Angular 20.3.3 Update + Enhanced NPM Discoverability - Minor Version Release

Updated

  • Angular Framework: Updated to Angular 20.3.3 (latest stable release)

    • @angular/core: ^20.3.2^20.3.3
    • @angular/common: ^20.3.2^20.3.3
    • @angular/forms: ^20.3.2^20.3.3
    • @angular/platform-browser: ^20.3.2^20.3.3
    • @angular/platform-browser-dynamic: ^20.3.2^20.3.3
    • @angular/router: ^20.3.2^20.3.3
    • @angular/animations: ^20.3.2^20.3.3
    • @angular/compiler: ^20.3.2^20.3.3
  • Angular Development Tools: Updated to 20.3.3

    • @angular/cli: ^20.3.2^20.3.3
    • @angular/compiler-cli: ^20.3.2^20.3.3
    • @angular-devkit/build-angular: ^20.3.2^20.3.3
    • ng-packagr: ^20.3.0 (latest available)
  • Peer Dependencies: Updated to reflect latest Angular version

    • Library now requires Angular 20.3.3+ for optimal compatibility

Added

  • NPM Keywords: Added comprehensive keywords for better search discoverability

    • Core terms: angular, country, selector, dropdown, picker, flags
    • Technical terms: angular-material, autocomplete, typescript, reactive-forms
    • SEO terms: country-picker, country-flags, mat-autocomplete, iso-codes
    • Framework terms: angular-20, ngx, component, ui-component
  • Enhanced Package Metadata:

    • Added detailed description for npm listing
    • Added author information
    • Added license field (MIT)
    • Added homepage and bug report URLs
    • Improved package.json structure for better npm presentation

Benefits

  • 🔧 Latest Bug Fixes: Includes all Angular 20.3.3 bug fixes and improvements
  • 🛡️ Security Updates: Latest security patches from Angular team
  • Performance: Enhanced performance optimizations from Angular 20.3.3
  • 🔄 Compatibility: Better compatibility with other Angular 20.3.3+ packages
  • Stability: Improved stability and reliability
  • �🔍 Better Search Results: Library now appears in relevant npm searches
  • 📊 Increased Visibility: More discoverable through various search terms
  • 📋 Professional Listing: Complete package information on npm
  • 🎯 Targeted Keywords: Covers Angular, Material Design, country selection use cases

Search Terms Now Supported

Users can now find the library by searching for:

  • angular country selector
  • angular country picker
  • angular country dropdown
  • angular material country
  • ngx country flags
  • angular autocomplete country
  • country selector component
  • And many more combinations

Migration Notes

  • Recommended: Update your Angular application to 20.3.3 for best compatibility
  • Backward Compatible: Still works with Angular 20.x applications
  • Peer Dependencies: Library now specifies ^20.3.3 for optimal experience

Version Strategy

  • Minor Version Bump: 20.0.x20.1.0 (following semantic versioning)
  • Angular Alignment: Version reflects significant Angular framework update
  • Future Ready: Prepared for upcoming Angular releases

[20.0.2] - 2025-09-30

🔧 Performance Improvement

Fixed

  • Template Optimization: Improved @for loop tracking in country list template
    • Changed track country to track country.code for better change detection performance
    • More efficient rendering when country list updates
    • Prevents unnecessary DOM re-renders for unchanged countries

Technical Details

  • Enhanced Angular's change detection strategy for country dropdown options
  • Better performance when filtering or updating country lists
  • Follows Angular's best practices for @for directive tracking functions

[20.0.1] - 2025-09-29

🚀 Performance & Stability Update

Added

  • Zoneless Change Detection: Migrated to Angular 20's modern zoneless change detection for better performance
  • Missing password field in demo form (was causing validation issues)
  • Enhanced form validation state management for Angular 20 compatibility

Fixed

  • CRITICAL: Form validation issues after Angular 19→20 migration
    • Fixed ControlValueAccessor implementation in country selector component
    • Resolved validation timing issues with custom form controls
    • Proper validation state synchronization between component and parent forms
  • Form submission validation - now correctly validates all required fields
  • Merge conflicts resolution maintaining zoneless implementation
  • Missing password input field in demo application

Improved

  • Performance: Removed zone.js dependency for smaller bundle size and faster change detection
  • Cleaner ControlValueAccessor implementation without manual change detection calls
  • Modern signal-based reactive patterns throughout the application
  • Better error handling and debugging support for form validation

Changed

  • BREAKING (Development): Removed zone.js dependency - applications can now optionally use zoneless change detection
  • Updated app configuration to use provideZonelessChangeDetection()
  • Simplified component lifecycle management without manual change detection
  • Enhanced form control validation patterns for Angular 20

Bundle Size

  • Reduced JavaScript bundle size by removing zone.js dependency
  • Faster application startup and runtime performance

Migration Notes

  • Applications can now optionally migrate to zoneless change detection
  • Existing zone-based applications will continue to work normally
  • Form validation is now more reliable and Angular 20 compliant

[20.0.0] - 2025-09-25

🚀 Major Update: Angular 20 Support

Changed

  • BREAKING CHANGE: Updated to Angular 20 from Angular 19.1.x
  • Updated all Angular dependencies to version 20.x
  • Updated Angular Material to 20.2.5 (latest compatible version)
  • Updated Angular CDK to 20.2.5
  • Updated ng-packagr to 20.3.0
  • Updated TypeScript to 5.8.0
  • Library major version now matches Angular major version (20.x.x)

Dependencies Updated

  • @angular/core: ^19.1.2^20.0.0
  • @angular/common: ^19.1.2^20.0.0
  • @angular/material: ^19.1.0^20.2.5
  • @angular/cdk: ^19.1.0^20.2.5
  • All other Angular packages updated to 20.x
  • ng-packagr: ^19.1.0^20.3.0
  • typescript: ~5.5.2~5.8.0

Migration Notes

  • This is a major version update that requires Angular 20+
  • Applications using this library must be updated to Angular 20+ to maintain compatibility
  • No breaking changes in the library API - only Angular version compatibility updated
  • Compatible with any Angular 20.x version (20.0.0, 20.1.x, 20.2.x, 20.3.x, etc.)

Installation

npm install ngx-country-selector@20.0.0

Requirements

  • Angular 20+ (any 20.x version)
  • Node.js 18+ (recommended)

Versioning Strategy

Starting with this release, the library follows this versioning pattern:

  • Major version matches Angular major version (20.x.x for Angular 20)
  • Minor version for new features and enhancements
  • Patch version for bug fixes and minor improvements

[19.1.5] - 2025-09-25

Added

  • GitHub Releases integration
  • GitHub Packages publishing
  • Automated release notes generation
  • Enhanced CI/CD workflow

Fixed

  • Git repository URL format for npm publishing
  • Version conflict handling in publishing workflow

Changed

  • Improved publishing workflow with better error handling
  • Updated repository URL format to prevent npm warnings

[19.1.3] - Previous Release

Features

  • Angular Country Selector component
  • Angular 19.1.x compatibility
  • TypeScript support
  • SCSS styling support