Open In App

Angular PrimeNG Timeline Templates

Last Updated : 24 Jan, 2023
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 how to use the Timeline Component in Angular PrimeNG. 

Angular PrimeNG TimeLine Component Templates:

  • opposite: This is used to manipulate the data of the timeline event. It will change the data in the opposite order.
  • marker: This is used to manipulate the data of the timeline event. It will align the data in the center.
  • content: This is used to manipulate the data of the timeline event. It will show the data.

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: In the below code, we will make use of the above syntax to demonstrate the use of the Timeline Templates.

  • app.component.html:

HTML




<div style="text-align:center">
    <h1 style="color: green">GeeksforGeeks</h1>
    <h5>Angular PrimeNG Timeline Templates</h5>
  
    <p-timeline [value]="gfg" layout="vertical">
      <ng-template pTemplate="content" let-event>
          {{ event }}
      </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.scss"]
})
  
export class AppComponent {
    gfg: any[];
  
    ngOnInit() {
        this.gfg = [
            "DSA Self Paced",
            "C++ STL",
            "System Design",
            "Java"
        ];
    }
}


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


Output:

 

Example 2: In the below code, we will make use of the above syntax to demonstrate the use of the Timeline Templates.

  • app.component.html:

HTML




<div style="text-align:center">
    <h1 style="color: green">GeeksforGeeks</h1>
    <h5>Angular PrimeNG Timeline Templates</h5>
  
    <p-timeline [value]="gfg" layout="vertical">
      <ng-template pTemplate="opposite" let-event>
          {{ event }}
      </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.scss"]
})
  
export class AppComponent {
    gfg: any[];
  
    ngOnInit() {
        this.gfg = [
            "DSA Self Paced",
            "C++ STL",
            "System Design",
            "Java"
        ];
    }
}


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


Output:

 

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads