Open In App

Angular PrimeNG Timeline Opposite

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 Opposite in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

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

Syntax:

<p-timeline [value]="....">
    <ng-template pTemplate="content" let-event>
        ...
    </ng-template>

    <ng-template pTemplate="opposite" let-event>
        ...
    </ng-template>
</p-timeline>

 

Angular PrimeNG Timeline Opposite properties:

  • value: It is an array of events to display. It is of array data type & the default value is null.

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

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

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Opposite</h5>
  
<p-timeline [value]="gfgCourse">
    <ng-template pTemplate="content" let-event>
        <small class="p-text-secondary">
          {{event.courseNumner}}
        </small>
    </ng-template>
  
    <ng-template pTemplate="opposite" let-event>
        {{event.courseName}}
    </ng-template>
</p-timeline>


  • 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.scss'],
})
export class AppComponent {
    gfgCourse: any[];
  
    ngOnInit() {
        this.gfgCourse = [
            {
              courseNumner: 'Course 1',
              courseName: 'DSA Self Paced',
            },
            {
              courseNumner: 'Course 2',
              courseName: 'C++ STL',
            },
            {
              courseNumner: 'Course 3',
              courseName: 'System Design',
            },
            {
              courseNumner: 'Course 4',
              courseName: 'Test Series',
            },
        ];
    }
}


  • 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: This is another example code that illustrates the use of Angular PrimeNG Timeline Opposite.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Timeline Opposite</h5>
  
<p-timeline [value]="gfgTutorial">
    <ng-template pTemplate="content" let-event>
        <small class="p-text-secondary">
          {{event.tutorialNumber}}
        </small>
    </ng-template>
  
    <ng-template pTemplate="opposite" let-event>
        {{event.tutorialName}}
    </ng-template>
</p-timeline>


  • 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.scss'],
})
export class AppComponent {
    gfgTutorial: any[];
  
    ngOnInit() {
        this.gfgTutorial = [
          {
            tutorialNumber: 'Tutorial 1',
            tutorialName: 'React Tutorial',
          },
          {
            tutorialNumber: 'Tutorial 2',
            tutorialName: 'Angular Tutorial',
          },
          {
            tutorialNumber: 'Tutorial 3',
            tutorialName: 'JavaScript Tutorial',
          },
          {
            tutorialNumber: 'Tutorial 4',
            tutorialName: 'C++ Tutorial',
          },
       ];
    }
}


  • 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



Last Updated : 23 Oct, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads