Angular PrimeNG Form Calendar Templates 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. This article will show us how to use the Angular PrimeNG Form Calendar Templates Component.
The Calendar Component is used to display a month-wise calendar that allows the user to select dates and move to the next or previous month.
Angular PrimeNG Form Calendar Templates:
- header: It is used to define the header.
- footer: It is used to define the footer.
- decade: $implicit It is an array containing the start and year of a decade to display at the header of the year picker.
- date: $implicit It is a value of the component.
Syntax:
<p-calendar [(ngModel)]="..."> <ng-template pTemplate="header"> ... </ng-template> </p-calendar>
Creating Angular application & Module Installation:
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Step 3: Install PrimeNG in your given directory.
npm install primeng --save npm install primeicons --save
Project Structure: It will look like the following.
Example1: In the below code, we will make use of the above template to demonstrate the use of the Header template of the calendar component.
- app.component.html:
HTML
< div style = "text-align:center;" > < h1 style = "color:green;" >w3wiki</ h1 > < h3 >A computer science portal for Beginner</ h3 > < h4 >Angular PrimeNG Form Calendar Templates Component </ h4 > < h5 >Template: "Header"</ h5 > < div class = "p-fluid p-grid p-formgrid" > < div class = "p-field p-col-4 p-md-4" > < label for = "basic" >GfG</ label > < p-calendar [(ngModel)]="date1"> < ng-template pTemplate = "header" > Header </ ng-template > </ p-calendar > </ div > </ div > </ div > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { date1?: Date; } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { FormsModule } from '@angular/forms' ; 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 { } |
Output:
Example2: In the below code, we will make use of the above template to demonstrate the use of the Footer template of the calendar component.
- app.component.html:
HTML
< div style = "text-align:center;" > < h1 style = "color:green;" >w3wiki</ h1 > < h3 >A computer science portal for Beginner</ h3 > < h4 >Angular PrimeNG Form Calendar Templates Component </ h4 > < h5 >Template: "Footer"</ h5 > < div class = "p-fluid p-grid p-formgrid" > < div class = "p-field p-col-4 p-md-4" > < label for = "basic" >GfG</ label > < p-calendar [(ngModel)]="date1"> < ng-template pTemplate = "footer" > Footer </ ng-template > </ p-calendar > </ div > </ div > </ div > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { date1?: Date; } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { FormsModule } from '@angular/forms' ; 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 { } |
Output:
Reference: https://www.primefaces.org/primeng/calendar
Contact Us