Angular PrimeNG的时间轴对齐

Angular PrimeNG的时间轴对齐

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

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

语法:

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

Angular PrimeNG时间轴对齐属性:

  • value。它是一个要显示的事件数组。它是数组的数据类型,默认值为空。
  • align: 它是时间线条相对于内容的位置。它是字符串数据类型,默认值为左。

创建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:这是一个基本的示例代码,说明了使用align=”left”的Angular PrimeNG时间轴对齐方式。

  • app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Alignment</h5>
  
<p-timeline [value]="gfg" align="left">
    <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 Alignment使用align=”right”。

  • app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Alignment</h5>
  
<p-timeline [value]="gfg" align="right">
    <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教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程