Angular PrimeNG表格日历弹出和内联组件

Angular PrimeNG表格日历弹出和内联组件

Angular PrimeNG是一个由谷歌开发和维护的Angular框架的UI组件集合。它使开发人员能够在更短的时间内开发出可扩展和响应式的界面,从而提高生产力。在这篇文章中,我们将看到Angular PrimeNG表格日历弹出和内联组件。

日历组件用于输入用户的日期和时间。默认情况下,日历是以弹出模式显示的,但可以使用inline属性以inline模式显示它。

Angular PrimeNG表格日历弹出和内联属性:

  • inline:如果这个属性被设置为 “true”,日历将以内联模式显示。

语法:

<p-calendar
    [inline]="true"
    [(ngModel)]="....">
</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:这个例子显示了日历组件的弹出模式。它在默认情况下是启用的。

<h2 style="color: green">GeeksforGeeks</h2>
<h4>
  Angular PrimeNG Form Calendar
  Popup and Inline Component
</h4>
  
<h3>Calendar In Popup Mode</h3>
<p-calendar [(ngModel)]="calendarVal">
</p-calendar>
import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
})
  
export class AppComponent {
    calendarVal?: Date;
}
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,
        FormsModule,
        CalendarModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }

输出:

Angular PrimeNG表格日历弹出和内联组件

例2:在这个例子中,我们将日历组件的inline属性设置为true,以便以inline模式显示。

<h2 style="color: green">GeeksforGeeks</h2>
<h4>
    Angular PrimeNG Form Calendar 
    Popup and Inline Component
</h4>
  
<h3>Calendar In Popup Mode</h3>
<p-calendar [inline]="true"
            [(ngModel)]="calendarVal">
</p-calendar>
import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
})
  
export class AppComponent {
    calendarVal?: Date;
}
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,
        FormsModule,
        CalendarModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }

输出:

Angular PrimeNG表格日历弹出和内联组件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程