Angular10 getLocaleCurrencyName() Function - GeeksforGeeks

28 Apr, 2021
In this article, we are going to see what is getLocaleCurrencyName in Angular 10 and how to use it.
The getLocaleCurrencyName is used to get the currency name for the given locale.
Syntax:
getLocaleCurrencyName(locale: string): string | null

NgModule: Module used by getLocaleCurrencyName is:
CommonModule
Approach:
Create the angular app to be used
In app.module.ts import LOCALE_ID because we need locale to be imported for using get getLocaleCurrencyName .
import { LOCALE_ID, NgModule } from '@angular/core';
In app.component.ts import getLocaleCurrencyName and LOCALE_ID
inject LOCALE_ID as a public variable and write the code for getting first day of week using locale variable.
In app.component.html show the local variable using string interpolation
serve the angular app using ng serve to see the output.
Parameters:
locale: A string containing locale code with rules.
Return value:
string : String containing the currency name.
Example 1:
app.module.ts
import { LOCALE_ID, NgModule }         from '@angular/core';import { BrowserModule }         from '@angular/platform-browser';  import { AppRoutingModule }         from './app-routing.module';import { AppComponent }         from './app.component';  @NgModule({  declarations: [    AppComponent  ],  imports: [    BrowserModule,    AppRoutingModule  ],  providers: [      { provide: LOCALE_ID, useValue: 'en-GB' },  ],  bootstrap: [AppComponent]})export class AppModule { }
app.component.ts
import {FormStyle,        getLocaleCurrencyName,         TranslationWidth }         from '@angular/common';  import {Component,         Inject,OnInit,         LOCALE_ID }         from '@angular/core';  @Component({    selector: 'app-root',    templateUrl: './app.component.html'})export class AppComponent {    curr = getLocaleCurrencyName(this.locale);    constructor(        @Inject(LOCALE_ID) public locale: string,){}      }
app.component.html
<h1>   GeeksforGeeks</h1><p>Locale Currency Name is :    {{curr}}</p>
Output:
Example 2:
app.module.ts
import { LOCALE_ID, NgModule }        from '@angular/core';import { BrowserModule }         from '@angular/platform-browser';  import { AppRoutingModule }         from './app-routing.module';import { AppComponent }         from './app.component';  @NgModule({  declarations: [    AppComponent  ],  imports: [    BrowserModule,    AppRoutingModule  ],  providers: [      { provide: LOCALE_ID, useValue: 'en-GB' },  ],  bootstrap: [AppComponent]})export class AppModule { }
app.component.ts
import {FormStyle,        getLocaleCurrencyName,         TranslationWidth }         from '@angular/common';  import { Component,         Inject,OnInit,         LOCALE_ID }         from '@angular/core';  @Component({    selector: 'app-root',    templateUrl: './app.component.html'})export class AppComponent {    curr = getLocaleCurrencyName(this.locale);    constructor(        @Inject(LOCALE_ID) public locale: string,){}      }
app.component.html
<h1>   GeeksforGeeks</h1><p>Currency Name is : {{curr}},    example: ( {{100 | currency}})</p>
Output:
Reference: https://angular.io/api/common/getLocaleCurrencyName 
Angular10
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular PrimeNG Dropdown Component
Angular PrimeNG Calendar Component
Angular PrimeNG Messages Component
Angular 10 (blur) Event
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?