Angular PrimeNG时间线布局

Angular PrimeNG时间线布局

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架用来做响应式网站非常方便。本文将向我们展示如何在Angular PrimeNG中使用时间线布局。我们还将学习一些属性,以及在代码中使用的语法。

时间线组件用于显示进程的时间线。

语法:

<p-timeline [value]="...." layout="....">
    <ng-template pTemplate="content" let-event>
        {{event}}
    </ng-template>
</p-timeline>

Angular PrimeNG时间线布局属性:

  • value。它是一个要显示的事件数组。它是数组的数据类型,默认值为空。
  • layout。它是时间线的方向。它是字符串数据类型,默认值是垂直。

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

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

ng new appname

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

cd appname

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

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

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

Angular PrimeNG时间线布局

运行应用程序的步骤:运行以下命令。

ng serve --open

例子1:这是一个基本的例子代码,说明了Angular PrimeNG时间线布局使用 layout=”vertical”。

  • app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Layout</h5>
  
<p-timeline [value]="gfg" layout="vertical">
    <ng-template pTemplate="content" let-event>
        {{event}}
    </ng-template>
</p-timeline>
  • app.component.ts:
import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.scss"]
})
export class AppComponent {
    gfg: any[];
  
    ngOnInit() {
        this.gfg = [
            "DSA Self Paced", 
            "C++ STL", 
            "System Design", 
            "Java"
        ];
    }
}
  • app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { TimelineModule } from 'primeng/timeline';
import { CardModule } from 'primeng/card';
import { ButtonModule } from 'primeng/button';
import { AppComponent } from './app.component';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FormsModule,
        ButtonModule,
        TimelineModule,
        CardModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}

输出:

Angular PrimeNG时间线布局

示例2:这是另一个示例代码,说明了Angular PrimeNG Timeline Layout使用layout=”horizontal”。

  • app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Layout</h5>
  
<p-timeline [value]="gfg" layout="horizontal">
    <ng-template pTemplate="content" let-event>
        {{event}}
    </ng-template>
</p-timeline>
  • app.component.ts:
import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.scss"]
})
export class AppComponent {
    gfg: any[];
  
    ngOnInit() {
        this.gfg = [
            "DSA Self Paced", 
            "C++ STL", 
            "System Design", 
            "Java"
        ];
    }
}
  • app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { TimelineModule } from 'primeng/timeline';
import { CardModule } from 'primeng/card';
import { ButtonModule } from 'primeng/button';
import { AppComponent } from './app.component';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        FormsModule,
        ButtonModule,
        TimelineModule,
        CardModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}

输出:

Angular PrimeNG时间线布局

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程