Open In App

Angular10 getLocaleEraNames() Function

In this article, we are going to see what is getLocaleEraNames in Angular 10 and how to use it.

The getLocaleEraNames is used to get the Gregorian-calendar eras for the given locale.



Syntax:

getLocaleEraNames(locale: string, width: TranslationWidth)

NgModule: Module used by getLocaleEraNames is:



Approach: 

import { LOCALE_ID, NgModule } from '@angular/core';

Parameters:

Return value:

Example 1:




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 { }




import {FormStyle,
        getLocaleEraNames, 
        TranslationWidth } 
        from '@angular/common';
  
import {Component, 
        Inject,OnInit, 
        LOCALE_ID } 
        from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    code = getLocaleEraNames(this.locale, 
           TranslationWidth.Wide);
    constructor(
        @Inject(LOCALE_ID) public locale: string,){}
      }




<h1>
   GeeksforGeeks
</h1>
 <p>Era Names is : {{code}}</p>

Output:

Example 2:




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 { }




import {FormStyle,
        getLocaleEraNames, 
        TranslationWidth } 
        from '@angular/common';
  
import {Component, 
        Inject,
        OnInit, 
        LOCALE_ID } 
        from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    era = getLocaleEraNames(this.locale, 
            TranslationWidth.Wide);
    a='';
    b='';
    constructor(
        @Inject(LOCALE_ID) public locale: string,){
            if(this.era[0]=='Before Christ'){
                this.a='BC';
                this.b='AD';
            }
        }
      }




<h1>
   GeeksforGeeks
</h1>
 <p>Era Names:
   <li>{{a}}</li>
   <li>{{b}}</li>
 </p>

Output:

Reference: https://angular.io/api/common/getLocaleEraNames


Article Tags :