Open In App

Angular PrimeNG Sidebar Animation Configuration

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 Sidebar Animation Configuration in Angular PrimeNG.

Sidebar component: It is used to make an element that overlays at the edges of the screen.



Angular PrimeNG Sidebar Animation Configuration properties:

Syntax:



<p-sidebar 
    [(visible)]="...." 
    [transitionOptions]="'...'">
</p-sidebar>

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: This is the basic example that illustrates how to use the Sidebar Animation Configuration in Angular PrimeNG.

app.component.html:




<p-sidebar
    [(visible)]="visibleSidebar1"
    [baseZIndex]="10000"
    [(visible)]="display"
    [transitionOptions]="'3000ms'">
    <h1 style="font-weight: normal;">GeeksforGeeks</h1>
    <p>Angular PrimeNG Sidebar Animation Configuration</p>
    <p-button
        type="button"
        (click)="visibleSidebar1 = false"
        label="ok"
        styleClass="p-button-info">
      </p-button>
    <p-button
        type="button"
        (click)="visibleSidebar1 = false"
        label="Cancel"
        styleClass="p-button-danger">
      </p-button>
</p-sidebar>
  
<p-button type="button" 
        (click)="visibleSidebar1 = true
        label="GfG">
</p-button>

app.component.ts:




import { Component } from "@angular/core";
import { PrimeNGConfig } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styles: [
        `
            :host ::ng-deep button {
                margin-right: 0.25em;
            }
        `
    ]
})
  
export class AppComponent {
    visibleSidebar1;
    constructor(private primengConfig: PrimeNGConfig) {}
  
    ngOnInit() {
        this.primengConfig.ripple = true;
    }
}

app.module.ts:




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { ButtonModule } from "primeng/button";
import { SidebarModule } from "primeng/sidebar";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        SidebarModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}

Output:

Angular PrimeNG Sidebar Animation Configuration

Example 2: This is another example that illustrates how to use the Sidebar Animation Configuration in Angular PrimeNG.

app.component.html:




<p-sidebar
    [(visible)]="visibleSidebar3"
    position="right"
    [baseZIndex]="100000"
    [(visible)]="display"
    [transitionOptions]="'3000ms'">
    <h1 style="font-weight: normal;">GeeksforGeeks</h1>
    <p-button
        type="button"
        (click)="visibleSidebar3 = false"
        label="Save"
        styleClass="p-button-info">
      </p-button>
    <p-button
        type="button"
        (click)="visibleSidebar3 = false"
        label="Cancel"
        styleClass="p-button-danger">
      </p-button>
</p-sidebar>
  
<p-button type="button" (click)="visibleSidebar3 = true" label="GfG"></p-button>

app.component.ts:




import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styles: [
    `
      :host ::ng-deep button {
          margin-right: .25em;
      }
  `,
  ],
})
export class AppComponent {
  visibleSidebar3;
  
  constructor(private primengConfig: PrimeNGConfig) {}
  
  ngOnInit() {
    this.primengConfig.ripple = true;
  }
}

app.module.ts:




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { ButtonModule } from "primeng/button";
import { SidebarModule } from "primeng/sidebar";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        SidebarModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}

Output:

Angular PrimeNG Sidebar Animation Configuration

Reference: https://www.primefaces.org/primeng/sidebar


Article Tags :