Open In App

Angular PrimeNG Timeline Custom Markers

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 learn how to use the Timeline Custom Markers in Angular PrimeNG.

The TimeLine component is used to display the timeline of the process. An alternative event marker can be used in place of the standard one using the marker template.



Angular PrimeNG  Timeline Custom Markers:

 



Syntax:

<ng-template pTemplate="marker" let-event>
   <span class="custom-marker p-shadow-2" 
       [style.backgroundColor]="...">
       <i [ngClass]="..."></i>
   </span>
</ng-template>

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:

 

ng serve --save

Example 1: Below is the example that illustrates the use of Angular PrimeNG Timeline Custom Markers.




<h1 style="color: green;">
  GeeksforGeeks
</h1>
<h5>Angular PrimeNG Timeline Custom Markers</h5>
  
<p-timeline [value]="gfg"
            align="alternate"
            layout="horizontal"
            styleClass="customized-timeline">
    <ng-template pTemplate="marker" let-event>
        <span class="custom-marker p-shadow-2"
              [style.backgroundColor]="event.color">
            <i [ngClass]="event.Icon"></i>
        </span>
    </ng-template>
  
    <ng-template pTemplate="content" let-event>
        <b>{{event.title}}</b>
        <br />
        <small>({{event.Date}})</small>
    </ng-template>
</p-timeline>




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 {
    gfg: any[];
  
    ngOnInit() {
        this.gfg = [
            {
                title: "Sourav Ganguly",
                Date: "2000-2006",
                Icon: PrimeIcons.ARROW_RIGHT,
                color: "#9C27B0"
            },
            {
                title: "Rahul Dravid",
                Date: "2003-2007",
                Icon: PrimeIcons.ARROW_RIGHT,
                color: "#673AB7"
            },
            {
                title: "Virender Sehwag",
                Date: "2005–2006",
                Icon: PrimeIcons.ARROW_RIGHT,
                color: "#FF9800"
            },
            {
                title: "Anil Kumble",
                Date: "2006–2007",
                Icon: PrimeIcons.ARROW_RIGHT,
                color: "#607D8B"
            },
            {
                title: "Dhoni",
                Date: "2008–2015",
                Icon: PrimeIcons.ARROW_RIGHT,
                color: "#99e2ff"
            },
            {
                title: "Virat Kohli",
                Date: "2015-2021",
                Icon: PrimeIcons.ARROW_RIGHT,
                color: "#99e200"
            },
            {
                title: "Rohit Sharma",
                Date: "2021-Present",
                Icon: PrimeIcons.ARROW_RIGHT,
                color: "#990000"
            }
        ];
    }
}




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

Output:

 

Example 2: Below is another example code that illustrates the use of Angular PrimeNG Timeline Custom Markers using some different custom markers.




<div style="text-align: center;">
    <h1 style="color: green;">
          GeeksforGeeks
      </h1>
    <h5>Angular PrimeNG Timeline Custom Markers</h5>
</div>
  
<p-timeline [value]="gfg"
            align="alternate"
            layout="vertical"
            styleClass="customized-timeline">
    <ng-template pTemplate="marker" let-event>
        <span class="custom-marker p-shadow-2"
              [style.backgroundColor]="event.color">
            <i [ngClass]="event.Icon"></i>
        </span>
    </ng-template>
  
    <ng-template pTemplate="content" let-event>
        <b>{{event.title}}</b>
        <br />
        <small>({{event.Date}})</small>
    </ng-template>
</p-timeline>




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 {
    gfg: any[];
  
    ngOnInit() {
        this.gfg = [
            {
                title: "1. Narendra Modi",
                Date: "26 May 2014 - Present",
                Icon: PrimeIcons.SORT_UP,
                color: "#9C27B0",
                ButtonColor: "p-button-rounded p-button-secondary"
            },
            {
                title: "2. Manmohan Singh",
                Date: "22 May 2004 to 26 May 2014",
                Icon: PrimeIcons.SORT_UP,
                color: "#673AB7",
                ButtonColor: "p-button-rounded p-button-primary"
            },
            {
                title: "3. Atal Bihari Vajpayee",
                Date: "19 March 1998 to 22 May 2004",
                Icon: PrimeIcons.SORT_UP,
                color: "#FF9800",
                ButtonColor: "p-button-rounded p-button-success"
            },
            {
                title: "4. Inder Kumar Gujral",
                Date: "21 April 1997 to 19 March 1998",
                Icon: PrimeIcons.SORT_UP,
                color: "#607D8B",
                ButtonColor: "p-button-rounded p-button-danger"
            },
            {
                title: "5. H. D. Deve Gowda",
                Date: "1 June 1996 to 21 April 1997",
                Icon: PrimeIcons.SORT_UP,
                color: "#99e2ff",
                ButtonColor: "p-button-rounded p-button-warning"
            },
            {
                title: "6. Atal Bihari Vajpayee",
                Date: "16 May 1996 to 1 June 1996",
                Icon: PrimeIcons.SORT_UP,
                color: "#99e200",
                ButtonColor: "p-button-rounded p-button-help"
            }
        ];
    }
}




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

Output:

 

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


Article Tags :