Angular PrimeNG时间线交替排列

Angular PrimeNG时间线交替排列

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架用于制作响应式网站,非常容易。本文将向我们展示如何在Angular PrimeNG中使用时间线交替对齐。我们还将学习属性,以及在代码中使用的语法。

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

语法:

<p-timeline [value]="...." align="alternate">
    <ng-template pTemplate="opposite" let-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:这是说明Angular PrimeNG Timeline Alternate Align.使用的基本例子代码。

  • app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Alternate Align</h5>
  
<p-timeline [value]="gfgTutorial" align="alternate">
    <ng-template pTemplate="opposite" let-event>
         {{event.tutorialName}}
    </ng-template>
</p-timeline>
  • app.component.ts:
import { Component } from '@angular/core';
import { PrimeIcons } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss'],
})
export class AppComponent {
    gfgTutorial: any[];
  
    ngOnInit() {
        this.gfgTutorial = [
          {
            tutorialName: 'React Tutorial',
          },
          {
            tutorialName: 'Angular Tutorial',
          },
          {
            tutorialName: 'JavaScript Tutorial',
          },
          {
            tutorialName: 'C++ Tutorial',
          },
        ];
    }
}
  • 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 Alternate Align的使用。

  • app.component.html:
<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Alternate Align</h5>
  
<p-timeline [value]="gfgCourses" align="alternate">
    <ng-template pTemplate="opposite" let-event>
         {{event.tutorialName}}
    </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 {
    gfgCourses: any[];
  
    ngOnInit() {
        this.gfgCourses = [
          {
            tutorialName: 'DSA Self Paced',
          },
          {
            tutorialName: 'System Design',
          },
          {
            tutorialName: 'C++ STL',
          },
          {
            tutorialName: 'Competitive Programming',
          },
        ];
    }
}
  • 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教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程