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

Package detail

@angular-material-extensions/select-country

Angular Material component that allow users to select a country or nationality

ng, library, angular, material, material design, ssr, select country, country picker, country dropdown, countries, nationality, languages

readme

angular-material-extensions's logo

@angular-material-extensions/select-country - Angular Material component that allow users to select a country or nationality with an autocomplete feature

npm version npm demo docs: typedoc Join the chat at https://gitter.im/angular-material-extensions/Lobby Build Status codecov Greenkeeper Badge license

@angular-material-extensions/select-country demonstration

@angular-material-extensions/select-country demonstration

Built by and for developers :heart:

Do you have any question or suggestion ? Please do not hesitate to contact us! Alternatively, provide a PR | open an appropriate issue here

If you like this project, support angular-material-extensions by starring :star: and sharing it :loudspeaker:

Table of Contents

Demo

View all the directives and components in action at https://angular-material-extensions.github.io/select-country

Library's components

  • <mat-select-country> used to display the main component

Dependencies

  • Angular developed and tested with 17.x

Installation

If Angular Material Design is not setup, just run ng add @angular/material learn more

Now add the library via the angular schematics

ng add @angular-material-extensions/select-country

2. Install via npm. (Alternative)

Install peer dependencies

npm i svg-country-flags -s

then update your angular.json like below (svg-country-flags)

"assets": [
              "src/favicon.ico",
              "src/assets",
              {
                "glob": "**/*",
                "input": "./node_modules/svg-country-flags/svg",
                "output": "src/assets/svg-country-flags/svg"
              }
            ],

Now install @angular-material-extensions/select-country via:

npm install --save @angular-material-extensions/select-country

Import the library

If you installed the library via angular schematics, you can skip this step

Once installed you need to import the main module and the HttpClientModule:

import { MatSelectCountryModule } from "@angular-material-extensions/select-country";
import { MatSelectCountryModule } from '@angular-material-extensions/select-country';
import {HttpClientModule} from '@angular/common/http';

@NgModule({
  declarations: [AppComponent, ...],
  imports: [
              MatSelectCountryModule.forRoot('de'), // you can use 'br' | 'de' | 'en' | 'es' | 'fr' | 'hr' | 'hu' | 'it' | 'nl' | 'pt' --> MatSelectCountrySupportedLanguages
             HttpClientModule, ...],
  bootstrap: [AppComponent]
})
export class AppModule {
}

in other modules

import { MatSelectCountryModule } from '@angular-material-extensions/select-country';
import {HttpClientModule} from '@angular/common/http';

@NgModule({
  declarations: [AppComponent, ...],
  imports: [MatSelectCountryModule, HttpClientModule, ...],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Other modules in your application like for lazy loading import MatSelectCountryModule into your feature module:

API

<mat-select-country> used to display the main component - see the demo examples

option bind type default description
value Input() Country - the selected country (pass an empty Country object with alpha2 code populated to do alpha2 lookup)
appearance Input() MatFormFieldAppearance - Possible appearance styles for mat-form-field ('legacy', 'standard', 'fill' or 'outline')
countries Input() Country[] All countries stored in the lib Countries that should be loaded - predefine the countries that you only need!
label Input() boolean - mat-form-field label's text
itemsLoadSize Input() number - the number of countries that should be fetched --> improves the performance
placeHolder Input() boolean - input placeholder text
disabled Input() boolean - Whether the component is disabled
loading Input() boolean - Whether the component is loading
nullable Input() boolean - Whether the component is able to emit null
readonly Input() boolean - Whether the component is read only
tabIndex Input() number | string - Whether the component can be focused, and where it participates in sequential keyboard navigation
showCallingCode Input() boolean false Whether the component to show the country's calling code in the label and selection
class Input() string - Class attribute apply style to input text or validation ignore (optional)
language Input() string - the language, if not specified MatSelectCountryModule.forRoot('XX') will be used (optional)
name Input() string 'country' the attribute name of the input element
autocomplete Input() string - the attribute autocomplete of the input element, to avoid suggestion of some browsers put 'no'
onCountrySelected Output() EventEmitter<Country> - emits the selected country as object (see the interface below)
interface Country {
  name: string;
  alpha2Code: string;
  alpha3Code: string;
  numericCode: string;
  callingCode: string;
}

Usage

add the <mat-select-country> element to your template:

<mat-select-country>
</mat-select-country>

@angular-material-extensions/select-country demonstration

@angular-material-extensions/select-country demonstration

@angular-material-extensions/select-country demonstration

Use the library with reactive forms

option 1 with Reactive Forms

<mat-select-country appearance="outline"
                    label="Country"
                    [formControl]="countryFormControl"
                    (onCountrySelected)="onCountrySelected($event)">
</mat-select-country>

option 2 with Reactive Forms

<form [formGroup]="countryFormGroup">
    <div fxLayoutAlign="center">
      <mat-select-country appearance="outline"
                          label="Country"
                          class="className"
                          formControlName="country"
                          (onCountrySelected)="onCountrySelected($event)">
      </mat-select-country>
    </div>
  </form>
import {Component,OnInit} from '@angular/core';
import {FormControl} from '@angular/forms';

import {Country} from '@angular-material-extensions/select-country';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{
  title = 'select-country';

  countryFormControl = new FormControl();
  countryFormGroup: FormGroup;

  constructor(private formBuilder: FormBuilder) {
    angulartics2GoogleAnalytics.startTracking();
  }

  ngOnInit(): void {

    this.countryFormGroup = this.formBuilder.group({
      country: []
    });

    this.countryFormGroup.get('country').valueChanges
.subscribe(country => console
.log('this.countryFormGroup.get("country").valueChanges', country));

    this.countryFormControl.valueChanges
.subscribe(country => console
.log('this.countryFormControl.valueChanges', country));
  }


  onCountrySelected($event: Country) {
    console.log($event);
  }
}

Predefine your countries to load

<mat-select-country appearance="outline"
                    label="Country"
                    [countries]="predefinedCountries"
                    (onCountrySelected)="onCountrySelected($event)">
</mat-select-country>
import {Country} from '@angular-material-extensions/select-country';

predefinedCountries: Country[] = [
  {
    name: 'Germany',
    alpha2Code: 'DE',
    alpha3Code: 'DEU',
    numericCode: '276',
    callingCode: '+49'
  },
  {
    name: 'Greece',
    alpha2Code: 'GR',
    alpha3Code: 'GRC',
    numericCode: '300',
    callingCode: '+30'
  },
  {
    name: 'France',
    alpha2Code: 'FR',
    alpha3Code: 'FRA',
    numericCode: '250',
    callingCode: '+33'
  },
  {
    name: 'Belgium',
    alpha2Code: 'BE',
    alpha3Code: 'BEL',
    numericCode: '056',
    callingCode: '+32'
  }
];

Result:

@angular-material-extensions/select-country demonstration

Improve performance - use the itemsLoadSize property

<mat-select-country appearance="outline"
                    label="Country"
                    [itemsLoadSize]="5">
</mat-select-country>

only 5 countries will fetched!

Change language dynamically - use the language property

<mat-select-country appearance="outline"
                    label="Country"
                    [language]="languageSelected"
                    (onCountrySelected)="onCountrySelected($event)">
</mat-select-country>

Run Demo App Locally

Build the library

$ npm run build:lib

Serve the demo app

$ npm start

Other Angular Libraries


Who is using this library?

nahaus.de - Digital and Automated Real Estate Management

To put your project here, please drop an appropriate PR


Support


jetbrains logo

This project is supported by jetbrains with 1 ALL PRODUCTS PACK OS LICENSE incl. webstorm


License

Copyright (c) 2020-2024 Anthony Nahas. Licensed under the MIT License (MIT)

angular-material-extensions's logo

changelog

16.0.0 (2023-11-19)

Bug Fixes

  • project: minor (a04507f)
  • project: updated deps (fbfba2c)
  • project: updated release it deps (2d4003b)
  • project: upgraded angular to v16 (825f87d)
  • project: upgraded angular universal to v16 (0193e83)
  • project: upgraded flex layout (e0f885a)

8.1.0 (2023-01-14)

8.0.0 (2022-11-30)

Bug Fixes

  • lib: adapt lib to v15 (4c26efe)
  • lib: upgraded angular core and cli to v15 (b7ac710)
  • lib: upgraded angular material to v15 (b494af5)
  • lib: upgraded angular peer deps (82f3fcc)
  • lib: upgraded angular universal (427c32b)

7.1.0 (2022-11-18)

7.0.1 (2022-07-04)

Bug Fixes

  • lib: minor (f7a6bc6)
  • lib: minor (7d5640f)
  • lib: upgeaded angular core and cli (89e48a8)
  • lib: upgeaded angular material (4c4a9ec)
  • lib: upgeaded angular universal (1fad261)

  • Merge remote-tracking branch 'origin/master' (dca4528)

  • fix(lib): minor (7d5640f)
  • Create FUNDING.yml (05aba23)

7.0.0 (2022-06-21)

Bug Fixes

  • lib: minor (e7a7c5c)
  • lib: upgraded angular deps (ae51ea4)
  • lib: upgraded angular material deps (b53a4e2)
  • lib: upgraded angular universal deps (7e9ad14)

6.0.1 (2022-01-05)

Bug Fixes

  • docs: updated the readme (da45022)

6.0.0 (2022-01-05)

Bug Fixes

  • lib: minor (91635af)
  • project: upgraded angular material to v13 (feb96cf)
  • project: upgraded angular material to v13 (c12f89d)
  • project: upgraded angular material to v13 (65d261a)
  • project: upgraded angular material to v13 (2d555fe)
  • project: upgraded angular material to v13 (d3f45e2)
  • project: upgraded angular to v13 (c5973ce)

5.1.0 (2021-10-14)

Bug Fixes

5.0.1 (2021-06-27)

5.0.0 (2021-06-05)

Bug Fixes

  • lib: upgraded angular material to v12 (021293d)
  • lib: upgraded to angular v12 (23a7928)

4.3.0 (2021-06-02)

Bug Fixes

  • lib: fixed focus with tabindex (998b259)
  • lib: minor (ae9442b)
  • lib: updated the dependencies (008e73f)
  • lib: updated the dependencies (779ab27)

Features

4.1.0 (2021-03-07)

Bug Fixes

4.0.3 (2021-01-17)

Bug Fixes

  • lib: match country on alpha2 (d304873)
  • lib: updated the dependencies (fb0e6ee)

4.0.2 (2021-01-07)

Bug Fixes

  • lib: removed json-utils helper file (98a6ddc)
  • lib: updated the dependencies (a779e00)

4.0.1 (2020-11-20)

4.0.0 (2020-11-20)

Bug Fixes

  • demo: upgraded angular flexlayout to v11 (fc7a45d)
  • lib: fixed issue related to the schematics (81eee08)
  • lib: updated dependencies (d093dd9)
  • lib: upgraded angular material to v11 (ef9e51e)
  • lib: upgraded angular to v11 (e7f1851)
  • lib: upgraded nguniversal to v11 (edcf027)
  • lib: upgraded rxjs to v6.6.3 (28f0cfa)

3.0.4 (2020-11-03)

Bug Fixes

  • norway alpha2code correctly set (f42390a)

3.0.3 (2020-11-03)

Bug Fixes

3.0.2 (2020-10-23)

Bug Fixes

  • join country name and alpha3 code if specified (13dcf4a)
  • rebase mistake (ab0cccd)

3.0.1 (2020-10-23)

Bug Fixes

  • lib: added the ability to disable the component using reactive forms #45 (19ed988)

3.0.0 (2020-10-23)

Bug Fixes

  • demo: adapted the demo app to the latest version (685c50b)
  • demo: enhanced the demo app #35 #46 (c8b2969)
  • i18n: improved i18n feature (3aee9f5)
  • lib: improved the lib - bug fixes - integration of i18n #7 #42 (62ca478)
  • lib: integration of the default en language #7 (8ac69d6)
  • lib: removed country property --> please use value #11 #35 (7ad05b5)
  • lib: solved default country bug #11 #35 (af00b88)
  • lib: solved minor bug #35 (7ade997)

Features

  • lib: added 4 languages support | de fr es it #7 (6253d00)
  • lib: added 4 languages support | de fr es it #7 (a3b440b)
  • lib: updated angular to the latest version (513175a)

2.2.0 (2020-08-30)

2.1.0 (2020-08-30)

Bug Fixes

  • lib: ability to predefince specific countries #12 #20 (a0269ad)
  • lib: ability to predefince specific countries #12 #20 (5db8bb8)
  • lib: ability to predefince specific countries #12 #20 (b3ecbb3)
  • lib: updated the dependencies (1cbc85c)

2.0.0 (2020-08-26)

Bug Fixes

  • lib: minor (58323d8)
  • lib: minor (60ce3cc)
  • lib: minor (4114362)
  • lib: updated the dependencies (f2a5488)
  • lib: upgraded to angular flex layout to v10 (c2a8826)
  • lib: upgraded to angular material to v10 (8fbc901)
  • lib: upgraded to angular v10 (6909825)

1.3.1 (2020-08-25)

Bug Fixes

  • lib: downgraded ng-packagr related module to v9 #31 #25 #24 #22 (2703ff2)
  • lib: fixed control value reset (14768bc)
  • lib: fixed github.io issue for deployed url (501ff1f)
  • lib: minor (2e3d1fe)
  • lib: removed again httpclient module from the library (65a19dd)
  • lib: updated the dependencies (d1c5f38)
  • lib: updated the dependencies (7f115c1)

1.3.0 (2020-07-08)

Bug Fixes

  • demo: enhanced the demo app (f17a3d2)
  • lib: downgraded angular cli (c07d650)
  • lib: removed HttpClientModule from the library (0c16689)
  • lib: updated angular to v9.1.11 (c08d8f7)
  • project: minor (215b69a)

  • fix(project): minor (215b69a)

  • Updating CHANGELOG.md for v1.2.1 (d835928)
  • Updating CHANGELOG.md for v1.2.1 (8d4f5c0)
  • Updating CHANGELOG.md for v1.2.1 (7d22a16)
  • fix(demo): enhanced the demo app (f17a3d2)
  • Updating CHANGELOG.md for v1.2.1 (91721dc)
  • Release 1.2.1 (ed727df)
  • Updating CHANGELOG.md for v1.2.1 (c0a619d)
  • fix(lib): removed HttpClientModule from the library (0c16689)
  • fix(lib): downgraded angular cli (c07d650)
  • fix(lib): updated angular to v9.1.11 (c08d8f7)

  • Updating CHANGELOG.md for v1.2.1 (8d4f5c0)

  • Updating CHANGELOG.md for v1.2.1 (7d22a16)
  • fix(demo): enhanced the demo app (f17a3d2)
  • Updating CHANGELOG.md for v1.2.1 (91721dc)
  • Release 1.2.1 (ed727df)
  • Updating CHANGELOG.md for v1.2.1 (c0a619d)
  • fix(lib): removed HttpClientModule from the library (0c16689)
  • fix(lib): downgraded angular cli (c07d650)
  • fix(lib): updated angular to v9.1.11 (c08d8f7)

  • Updating CHANGELOG.md for v1.2.1 (7d22a16)

  • fix(demo): enhanced the demo app (f17a3d2)
  • Updating CHANGELOG.md for v1.2.1 (91721dc)
  • Release 1.2.1 (ed727df)
  • Updating CHANGELOG.md for v1.2.1 (c0a619d)
  • fix(lib): removed HttpClientModule from the library (0c16689)
  • fix(lib): downgraded angular cli (c07d650)
  • fix(lib): updated angular to v9.1.11 (c08d8f7)

  • fix(demo): enhanced the demo app (f17a3d2)

  • Updating CHANGELOG.md for v1.2.1 (91721dc)
  • Release 1.2.1 (ed727df)
  • Updating CHANGELOG.md for v1.2.1 (c0a619d)
  • fix(lib): removed HttpClientModule from the library (0c16689)
  • fix(lib): downgraded angular cli (c07d650)
  • fix(lib): updated angular to v9.1.11 (c08d8f7)

  • Release 1.2.1 (ed727df)

  • Updating CHANGELOG.md for v1.2.1 (c0a619d)
  • fix(lib): removed HttpClientModule from the library (0c16689)
  • fix(lib): downgraded angular cli (c07d650)
  • fix(lib): updated angular to v9.1.11 (c08d8f7)

  • fix(lib): removed HttpClientModule from the library (0c16689)

  • fix(lib): downgraded angular cli (c07d650)
  • fix(lib): updated angular to v9.1.11 (c08d8f7)

  • fix(lib): updated angular material and cdk to v9.2.4 (c0ccd87)

  • fix(lib): updated angular to v9.1.7 (4fda96e)

  • fix(lib): updated the dependencies (cf0efa4)
  • Merge pull request #14 from wendannor/chore/add_missing_countries (d6e7550)
  • chore(countries) add some missing countries (cea5abc)

  • fix(lib): updated the dependencies (3bc0cc5)

  • fix(lib): updated angular material and cdk to v9.2.3 (706df7b)
  • fix(lib): updated angular to v9.1.7 (0fd3295)
  • Merge pull request #9 from hrynko/add-value-reset (45090a8)
  • Merge pull request #10 from hrynko/add-countries (3586ce5)
  • chore(lib): added Moldova, Panama and Uzbekistan (2c70f7a)
  • feat(lib): added logic of resetting value on input blur (ee41db8)
  • fix(lib): minor - added prod script (396b2ea)
  • fix(lib): minor - href fixed (5900bb7)
  • fix(lib): support of prerendering (8340714)

1.0.1 (2020-04-07)

Bug Fixes

  • lib: updated angular material to v9.2.0 (bdd9732)
  • lib: updated angular to v9.1.0 (9104541)

Features

  • lib: added input for mat-select-country value (cab5fb8)

1.0.0 (2020-02-08)

Bug Fixes

  • lib: updated the package.json file (1f04d8e)
  • lib: upgraded the library to angular v9 (9c0fe78)

1.0.0 (2020-02-08)

Bug Fixes

  • lib: updated the package.json file (1f04d8e)
  • lib: upgraded the library to angular v9 (9c0fe78)

1.0.0 (2020-02-08)

Bug Fixes

  • lib: updated the package.json file (1f04d8e)
  • lib: upgraded the library to angular v9 (9c0fe78)

1.0.0 (2020-02-08)

Bug Fixes

  • lib: upgraded the library to angular v9 (9c0fe78)

0.3.3 (2020-01-18)

Bug Fixes

  • package: updated dependencies (f6fb12b)

0.3.2 (2019-12-30)

Bug Fixes

  • package: added debounce time to the component (7374ae0)
  • package: updated angular and other dependencies (fa6852d)
  • package: updated gitignore file (51914b6)
  • package: updated manifest.json file (e06d19b)
  • package: updated metatags (d6a6731)
  • package: updated the npm scripts for prerendering (c9ea5e3)

0.3.1 (2019-11-21)

Bug Fixes

  • package: minor in schematics (c4e547e)

0.3.0 (2019-11-20)

Bug Fixes

  • package: improved the schematics (55b0660)

Features

  • project: integration of angular github pages (466de62)
  • project: integration of ssr and prerender (1f7817b)

0.2.1 (2019-11-17)

0.2.0 (2019-11-17)

Bug Fixes

  • demo: updated rxjs to v6.5.3 (1eb40ed)
  • demo: updated the demo app (81ef394)
  • project: updated the demo app (1d84386)
  • project: updated the project's deps (4d24aae)

Features

  • package: added label and placeHolder inputs to the component (da53880)
  • package: added readonly input (aa5ed2c)

0.1.13 (2019-11-14)

Bug Fixes

  • project: updated the hook of git release (06d50cc)

0.1.12 (2019-11-14)

Bug Fixes

0.1.11 (2019-11-14)

Bug Fixes

0.1.10 (2019-11-14)

Bug Fixes

  • project: enhanced the npm script (6ee590d)

0.1.9 (2019-11-14)

Bug Fixes

  • project: improved the release-it workflow (dcade43)

0.1.5 (2019-11-14)

Bug Fixes

  • project: moved the release-it workflow to the package.json file (59b185e)

0.1.4 (2019-11-14)

Bug Fixes

  • project: enhanced the release-it workflow (89b71c9)

0.1.3 (2019-11-14)

Bug Fixes

  • lib: updated npm scripts (c358b35)
  • package: adjusted the npm scripts (ea25a23)
  • package: adjusted the peer deps of the lib (8ce9b3a)
  • project: updated angular and other deps (b852328)

0.1.2 (2019-11-14)

Bug Fixes

  • package: adjust the path of changelog for release-it (173d34f)
  • package: minor (b344b13)
  • package: minor (2fe7e2b)

0.1.1 (2019-11-14)

Bug Fixes

  • package: updated the homepage of the lib (455e773)

0.1.0 (2019-11-14)

Bug Fixes

  • demo: updated the demo app (4fe1433)
  • package: added angular schematics support (a1b4fbc)
  • package: added npm scripts (e82f1ff)
  • package: improved the angular schematics support (83e9ca5)
  • package: improved the filter feature in mat autocomplete (c01d7bf)

Features

  • package: added countries list (31eec40)
  • package: generated @angular-material-extensions/select-country library (a995715)
  • package: integration of release-it (e6d2933)
  • package: integration of ssr (9dff4ec)
  • project: added angular material (dd5b81c)