Open In App

Angular 10 WeekDay API

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: 

Example:




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];
}




<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


Article Tags :