Open In App

Angular PrimeNG Timeline Customized

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 Customized Component in Angular PrimeNG. 

The TimeLine component is used to display the timeline of the process.



Syntax:

<p-timeline [value]="..." align="..." 
    styleClass="customized-timeline">
    <ng-template pTemplate="marker" let-event>
        <span class="custom-marker p-shadow-2" 
            [style.backgroundColor]="...">
            <i [ngClass]="..."></i>
        </span>
    </ng-template>
    <ng-template pTemplate="content" let-event>
        <p-card [header]="..." 
            [subheader]="..."> 
        </p-card>
    </ng-template>
</p-timeline>

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:

 

Steps to run the above file: Run the below command

ng serve --save

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

app.component.html:




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Customized</h5>
 
<p-timeline
    [value]="gfg" align="alternate"
    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>
        <p-card [header]="event.title"
            [subheader]="event.Date">
          </p-card>
    </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 {
    gfg: any[];
 
    ngOnInit() {
        this.gfg = [
            {
                title: "Babar",
                Date: "1526–1530",
                Icon: PrimeIcons.SORT_DOWN,
                color: "#9C27B0"
            },
            {
                title: "Humayun",
                Date: "I- 1530–1540, II – 1555–1556",
                Icon: PrimeIcons.SORT_DOWN,
                color: "#673AB7"
            },
            {
                title: "Akbar ",
                Date: "1556–1605",
                Icon: PrimeIcons.SORT_DOWN,
                color: "#FF9800"
            },
            {
                title: "Jahangir",
                Date: "1605–1627",
                Icon: PrimeIcons.SORT_DOWN,
                color: "#607D8B"
            },
            {
                title: "Shah Jahan",
                Date: "1628–1658",
                Icon: PrimeIcons.SORT_DOWN,
                color: "#99e2ff"
            },
            {
                title: "Aurangzeb",
                Date: "1658–1707",
                Icon: PrimeIcons.SORT_DOWN,
                color: "#99e200"
            },
            {
                title: "Bahadur Shah",
                Date: "1707–1712",
                Icon: PrimeIcons.SORT_DOWN,
                color: "#990000"
            }
        ];
    }
}

app.module:




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 that illustrates the use of Angular PrimeNG  Timeline Customized.

app.component.html:




<h1 style="color: green; text-align: center">GeeksforGeeks</h1>
<h5 style="text-align: center; margin-bottom: 50px">
  Angular PrimeNG Timeline Customized
</h5>
 
<p-timeline [value]="gfg" align="alternate"
    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>
        <button pButton pRipple type="button"
            label="{{event.title}}"
            class="{{event.ButtonColor}}">
        </button>
    </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 {
    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"
            }
        ];
    }
}

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

Output:

 

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


Article Tags :