Open In App

Angular PrimeNG Timeline Styling

Improve
Improve
Like Article
Like
Save
Share
Report

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. This article will show us about Angular PrimeNG Timeline Styling.

The TimeLine component is used to display the timeline of the process. This component helps to make the interactive Timeline by implementing the different stylings provided by Angular PrimeNG.

Angular PrimeNG Timeline 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.

Syntax:

<p-timeline [value]="...." align="....">
    <ng-template pTemplate="content" let-event>
         ......
     </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 application: Run the below command to see the output

ng serve --save

Example 1: Below is the basic example code that illustrates the use of the Angular PrimeNG Timeline Styling.

  • app.component.html:

HTML




<div style="width: 80%;">
    <h1 style="color: green;">GeeksforGeeks</h1>
    <h2>Angular PrimeNG Timeline Styling</h2>
    <p-timeline [value]="gfgCourses" align="left">
        <ng-template pTemplate="opposite" let-event>
            {{event.tutorialName}}
        </ng-template>
    </p-timeline>
</div>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
 
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
 
export class AppComponent {
    gfgCourses: any[] = [];
 
    ngOnInit() {
        this.gfgCourses = [
            {
                tutorialName: "DSA Self Paced"
            },
            {
                tutorialName: "System Design"
            },
            {
                tutorialName: "C++ STL"
            },
            {
                tutorialName: "Competitive Programming"
            }
        ];
    }
}


  • app.module.ts:

Javascript




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


  • app.component.css:

CSS




:host ::ng-deep .p-timeline{
      border: 2px solid green;
}


Output:

 

Example 2: Below is another example code that illustrates the use of the Angular PrimeNG Timeline Styling.

  • app.component.html:

Code block

  • app.component.ts:

Javascript




import { Component } from "@angular/core";
import { PrimeIcons } from "primeng/api";
 
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
 
export class AppComponent {
    gfgCourses: any[] = [];
 
    ngOnInit() {
        this.gfgCourses = [
            {
                tutorialName: "DSA Self Paced"
            },
            {
                tutorialName: "System Design"
            },
            {
                tutorialName: "C++ STL"
            },
            {
                tutorialName: "Competitive Programming"
            }
        ];
    }
}


  • app.module.ts:

Javascript




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


  • app.component.css:

CSS




:host ::ng-deep .p-timeline{
    background-color:  lightgreen;
    color: green;
    font-weight: bold;
}


Output:

 

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



Last Updated : 20 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads