In this article, we are going to see what is WeekDay in Angular 10 and how to use it. The WeekDay API in Angular10 is used to get the value for each day of the week.
Syntax:
enum WeekDay {
Sunday: 0
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
}
NgModule: Module used by WeekDay is:
Approach:
- Create an angular app that to be used.
- Import WeekDay to your app.component.ts file.
- Define week day variable in app.component.ts
- In app.component.html, use weekDay variable to get index values of week day.
- Serve the angular app using ng serve to see the output.
Example:
app.component.ts
import { Component, Inject } from '@angular/core' ;
import { PLATFORM_ID } from '@angular/core' ;
import { WeekDay } from '@angular/common' ;
import { isPlatformWorkerApp } from '@angular/common' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
public weekDays: WeekDay[] = [
WeekDay.Monday,
WeekDay.Tuesday,
WeekDay.Wednesday,
WeekDay.Thursday,
WeekDay.Friday,
WeekDay.Saturday,
WeekDay.Sunday];
}
|
app.component.html
< h1 >GeeksforGeeks</ h1 >
< select >
< option * ngFor = "let day of weekDays" value = "day" >
Day No:{{day}}
</ option >
</ select >
|
Output:

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