Angular PrimeNG表格日历动画配置组件
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架用于制作响应式网站,非常容易。本文将向我们展示如何使用Angular PrimeNG表格日历动画配置组件。
日历组件用于显示一个日历,允许用户选择日期并移动到下个月或上个月。动画配置组件用于设置动画的过渡时间,使用showTransitionOptions和hideTransitionOptions属性可以定制显示和隐藏动画的过渡。
Angular PrimeNG表格日历动画配置属性:
- showTransitionOptions。它指定了显示过渡的过渡选项。默认值是.12s cubic-bezier(0, 0, 0.2, 1)”。
- hideTransitionOptions。此属性指定了隐藏过渡的过渡选项。默认值是”.1s线性”。
语法:
<p-calendar
[(ngModel)]="dateValue"
[showTransitionOptions]="..."
[hideTransitionOptions]="...">
</p-calendar>
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
Project Structure:
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
Animation Configuration Component
</h4>
<h5> [showTransitionOptions]="'1500ms'" </h5>
<div class="p-fluid p-grid p-formgrid">
<div class="p-field p-col-12 p-md-4">
<label for="basic"></label>
<p-calendar
[(ngModel)]="date1"
[showTransitionOptions]="'1500ms'"
[hideTransitionOptions]="'0ms'">
</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 { }
输出:
示例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
Animation Configuration Component
</h4>
<h5>[hideTransitionOptions]="'3000ms'"</h5>
<div class="p-fluid p-grid p-formgrid">
<div class="p-field p-col-12 p-md-4">
<label for="basic"></label>
<p-calendar
[(ngModel)]="date1"
[hideTransitionOptions]="'3000ms'">
</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 { }
输出: