Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Angular PrimeNG TimeLine Component

  • Last Updated : 03 Oct, 2021

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease.

In this article, we will know how to use the TimeLine Component in Angular PrimeNG. We will also learn about the properties, styling along with their syntaxes that will be used in the code.

TimeLine component: It is used to display the timeline of the process.

Properties:

  • value: It is an array of events to display. It is of array data type & the default value is null.
  • align: It is the position of the timeline bar relative to the content. It is of string data type & the default value is left.
  • layout: It is the orientation of the timeline. It is of string data type & the default value is vertical.
  • style: It is the inline style of the component. It is of string data type & the default value is null.
  • styleClass: It is the style class of the component. It is of string data type & the default value is null.

 

Styling:

  • p-timeline: It is the container element.
  • p-timeline-left: It is the container element when alignment is left.
  • p-timeline-right: It is the container element when alignment is right.
  • p-timeline-top: It is the container element when alignment is top.
  • p-timeline-bottom: It is the container element when alignment is bottom.
  • p-timeline-alternate: It is the container element when alignment is alternating.
  • p-timeline-vertical: It is the container element of a vertical timeline.
  • p-timeline-horizontal: It is the container element of a horizontal timeline.
  • p-timeline-event: It is the event element.
  • p-timeline-event-opposite: It is the opposite of event content.
  • p-timeline-event-content: It is the event content.
  • p-timeline-event-separator: It is the separator element of an event.
  • p-timeline-event-marker: It is the marker element of an event.
  • p-timeline-event-connector: It is the connector element of an event.

Creating Angular application & module installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

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

Project Structure: It will look like the following:

TimeLine

 



Example 1: This is the basic example that shows how to use the Timeline component.

app.component.html




<div class="card">
  <h5>Left Align</h5>
  <p-timeline [value]="gfg">
    <ng-template pTemplate="content" let-event> 
      {{event.status}} 
    </ng-template>
  </p-timeline>
</div>
  
<div class="card">
  <h5>Right Align</h5>
  <p-timeline [value]="gfg" align="right">
    <ng-template pTemplate="content" let-event> 
      {{event.status}} 
    </ng-template>
  </p-timeline>
</div>
  
<div class="card">
  <h5>Alternate Align</h5>
  <p-timeline [value]="gfg" align="alternate">
    <ng-template pTemplate="content" let-event> 
      {{event.status}} 
    </ng-template>
  </p-timeline>
</div>

app.component.ts




import { Component } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.scss"],
})
export class AppComponent {
  gfg: any[];
  
  ngOnInit() {
    this.gfg = [
      {
        status: "Time 1",
      },
      {
        status: "Time 2",
      },
      {
        status: "Time 3",
      },
      {
        status: "Time 4",
      },
    ];
  }
}

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 { AppComponent } from "./app.component";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    TimelineModule,
    CardModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

TimeLine

Example 2: In this example, we will know how to use the layout property in the Timeline Component.

app.component.html




<h6>Top Align</h6>
<p-timeline [value]="arr" layout="horizontal" align="top">
  <ng-template pTemplate="content" let-event> 
    {{event.status}} 
  </ng-template>
</p-timeline>
  
<h6>Bottom Align</h6>
<p-timeline [value]="arr" layout="horizontal" align="bottom">
  <ng-template pTemplate="content" let-event> 
    {{event.status}} 
  </ng-template>
</p-timeline>
  
<h6>Alternate Align</h6>
<p-timeline [value]="arr" layout="horizontal" align="alternate">
  <ng-template pTemplate="content" let-event> 
    {{event.status}} 
  </ng-template>
  <ng-template pTemplate="opposite" let-event> 
        
  </ng-template>
</p-timeline>

app.component.ts




import { Component } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
})
export class AppComponent {
  arr: any[];
  
  ngOnInit() {
    this.arr = [
      {
        status: "Time1",
      },
      {
        status: "Time2",
      },
      {
        status: "Time3",
      },
      {
        status: "Time4",
      },
    ];
  }
}

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 { AppComponent } from "./app.component";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    TimelineModule,
    CardModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

TimeLine

Reference: https://primefaces.org/primeng/showcase/#/timeline


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!