1.0.0 • Published 4 years ago

ngx-countries v1.0.0

Weekly downloads
12
License
-
Repository
github
Last release
4 years ago

NgxCountriesLib

This project is a simple Angular wrapper for i18n-iso-countries and countries libraries.

It gets locales and translations from i81n-iso-countries and additional data (currency, flag, etc) from countries.

Installation

`npm install --save ngx-countries i18n-iso-countries'

'countries' lib is already bundled in ngx-countries as it doesn't export countries.json.

Usage

In your root module use forRoot method

import { BrowserModule } from '@angular/platform-browser';
import { NgxCountriesModule } from 'ngx-countries';
...

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxCountriesModule.forRoot({
      locales: ['en', 'it']
    }),
    ...
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Locales: see supported languages for i18n-iso-countries here.

You can pass a default locale (default to en):

NgxCountriesModule.forRoot({
  defaultLocale: 'it',
  locales: ['en', 'it', 'ja']
})

If no locales are passed, only default locale is used.

NgxCountriesModule.forRoot({
  defaultLocale: 'it'
})

If you pass no options in forRoot method only en is used as locale.

NgxCountriesModule.forRoot()

In you child modules you should just import NgxCountriesModule.

Example application

Run ng build ngx-countries to build the project. When done run ng serve demo and go to http://localhost:4200 in your favourite browser once compiled.

Running unit tests

Run ng test ngx-countries to execute the unit tests via Karma.