Open In App

Angular PrimeNG TimeLine Component

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:



 

Styling:

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:

 

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




<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>




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",
      },
    ];
  }
}




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:

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




<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>




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",
      },
    ];
  }
}




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:

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


Article Tags :