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:
- transitionOptions: It is used to set the transition options of the animation. It is of string data type & the default value is 150ms cubic-bezier(0, 0, 0.2, 1).
- style: It is used to set the inline style of the component. It is of string data type & the default value is null.
- styleClass: It is used to set the style class of the component. It is of string data type & the default value is null.
- visible: It specifies the visibility of the dialog. It is of the boolean data type, the default value is false.
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:
HTML
< p-sidebar [(visible)]="visibleSidebar1" [baseZIndex]="10000" [(visible)]="display" [transitionOptions]="'3000ms'"> < h1 style = "font-weight: normal;" >w3wiki</ 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:
Javascript
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:
Javascript
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:
Example 2: This is another example that illustrates how to use the Sidebar Animation Configuration in Angular PrimeNG.
app.component.html:
HTML
< p-sidebar [(visible)]="visibleSidebar3" position = "right" [baseZIndex]="100000" [(visible)]="display" [transitionOptions]="'3000ms'"> < h1 style = "font-weight: normal;" >w3wiki</ 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:
Javascript
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:
Javascript
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:
Contact Us