Getting started with nxt-flags

Installing

npm install --save nxt-flags

Import flags component

import { FlagComponent } from 'nxt-flags'

@Component({
    ...
    imports: [
        ...
        FlagComponent
    ]
})

Add flags SVGs to Angular compilation

{
    ...
    "assets": [
        ...,
        {
            "glob": "**/*",
            "input": "./node_modules/nxt-flags/assets/flags",
            "output": "./assets/flags"
        }
    ]
}

Include it in HTML template

Use the tag nxt-flag with attribute country="xx" (where xx is the ISO 3166-1-alpha-2 code of a country):

<nxt-flag country="br"></nxt-flag>

Load the flags from another folder or a CDN

The flags load from assets/flags/ by default, relative to the base href. Provide another path, or a function from a code to its URL, for the app or for the flags inside a component:

import { provideFlagsPath } from 'nxt-flags'

providers: [provideFlagsPath('/static/flags/')]
providers: [provideFlagsPath((code) => `https://cdn.example.com/flags/${code}.svg`)]

Accessible name

A flag is decorative by default, hidden from assistive technologies, e.g. beside the country's name. Give it a label where it stands on its own, and it's an image with that name:

<nxt-flag country="br" label="Brazil"></nxt-flag>

Configuration options

InputTypeDefault valueDescription
[country]FlagDatabaseKey | undefined

ISO 3166-1-alpha-2 country code

[label]string | undefined

The flag's accessible name, e.g. the country's name; with it, the flag is an image to assistive technologies. Without it, the flag is decorative and hidden from them, e.g. beside the country's name.

[format]FlagFormat'none'

Flag format

[size]number | FlagSizeAlias48

Flag width, either value in pixels or FlagSizeAlias