Open In App

Angular PrimeNG Calendar Component

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the calendar component in angular ngx bootstrap.

Calendar component: It is used to display a month-wise calendar that allows the user to select dates and move to the next or previous month.



Properties:

Events:



 

Styling:

Templates:

Methods:

Date Formats:

Creating Angular Application & Module  Installation:

Project Structure: It will look like the following.

 

Example 1: This is the basic example that shows how to use calendar component 




<h2>GeeksforGeeks</h2>
<h4>PrimeNg Calendar Component</h4>
<p-calendar [inline]="true" [showWeek]="true"></p-calendar>




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { BrowserAnimationsModule } from 
    "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
  
import { CalendarModule } from "primeng/calendar";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    CalendarModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}




import { Component } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
})
export class AppComponent {}

Output:

Example 2: we will use a popup style calendar. 




<div class="p-fluid p-grid p-formgrid">
  <div class="p-field p-col-12 p-md-4">
    <label>Basic</label>
    <p-calendar></p-calendar>
  </div>
  <div class="p-field p-col-12 p-md-4">
    <label>Calendar with Time</label>
    <p-calendar [showTime]="true"></p-calendar>
  </div>
</div>




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
  
import { CalendarModule } from "primeng/calendar";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    CalendarModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}




import { Component } from "@angular/core";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
})
export class AppComponent {}

Output:

Reference: https://primeng.org/calendar


Article Tags :