Angular PrimeNG表格日历模板组件

Angular PrimeNG表格日历模板组件

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架用于制作响应式网站,非常方便。本文将向我们展示如何使用Angular PrimeNG 表格日历模板组件

日历组件用于显示一个按月划分的日历,允许用户选择日期并移动到下个月或上个月。

Angular PrimeNG表格日历模板:

  • header。它用于定义页眉。
  • footer。它用于定义页脚。
  • decade: $implicit 它是一个数组,包含十年的开始和年份,显示在年份选择器的头部。
  • date。$implicit 它是一个组件的值。

语法:

<p-calendar [(ngModel)]="...">
    <ng-template pTemplate="header">
        ...
    </ng-template>
</p-calendar>

创建Angular应用程序和模块安装。

第1步:使用以下命令创建一个Angular应用程序。

ng new appname

第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。

cd appname

第3步:在你给定的目录中安装PrimeNG。

npm install primeng --save
npm install primeicons --save

项目结构:它将看起来像如下。

Angular PrimeNG表格日历模板组件

Project Structure

示例1:在下面的代码中,我们将利用上述模板来演示日历组件的标题模板的使用。

  • app.component.html:
<div style="text-align:center;">
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3>A computer science portal for geeks</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:
import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    date1?: Date;
}
  • app.module.ts:
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 { }

输出:

Angular PrimeNG表格日历模板组件

示例2:在下面的代码中,我们将利用上述模板来演示日历组件的页脚模板的使用。

  • app.component.html:
<div style="text-align:center;">
    <h1 style="color:green;">GeeksforGeeks</h1>
    <h3>A computer science portal for geeks</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:
import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    date1?: Date;
}
  • app.module.ts:
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 { }

输出:

Angular PrimeNG表格日历模板组件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程