Angular10 getLocaleWeekEndRange() Function
In this article, we are going to see what is getLocaleWeekEndRange in Angular 10 and how to use it. The getLocaleWeekEndRange is used to get the range of week days for the given locale.
Syntax:
getLocaleWeekEndRange(locale : string): [WeakDay, WeakDay]
NgModule: Module used by getLocaleWeekEndRange is:
Approach:
- Create an angular app.
- In app.module.ts, import LOCALE_ID because we need locale to be imported for using get getLocaleWeekEndRange.
import { LOCALE_ID, NgModule } from '@angular/core';
- In app.component.ts, import getLocaleWeekEndRange 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:
- array: array containing end day and start day.
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 {getLocaleWeekEndRange } from '@angular/common' ;
import { Component, Inject,OnInit, LOCALE_ID } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html'
})
export class AppComponent {
rn = getLocaleWeekEndRange( this .locale);
constructor(
@Inject(LOCALE_ID) public locale: string,){}
}
|
app.component.html
< h1 >
GeeksforGeeks
</ h1 >
< p >weekend range: {{rn}}</ 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 {getLocaleWeekEndRange } from '@angular/common' ;
import { Component, Inject, LOCALE_ID } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html'
})
export class AppComponent {
rn = getLocaleWeekEndRange( this .locale);
d1= '' ;
d2= '' ;
constructor(
@Inject(LOCALE_ID) public locale: string,){
if ( this .rn[0] == 6 && this .rn[1] == 0){
this .d1 = 'Monday' ;
this .d2 = 'Sunday' ;
}
}
}
|
app.component.html
< h1 >
GeeksforGeeks
</ h1 >
< p >weekend range is from {{d1}} to {{d2}}</ p >
|
Output:
Reference: https://angular.io/api/common/getLocaleWeekEndRange
Last Updated :
30 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...