Open In App
Related Articles

Angular 10 WeekDay API

Improve Article
Improve
Save Article
Save
Like Article
Like

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:

  • CommonModule

 

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


Last Updated : 14 Jun, 2021
Like Article
Save Article
Similar Reads
Related Tutorials