Angular PrimeNG Sidebar Properties
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. In this article, we will learn how to use the Sidebar Properties in Angular PrimeNG.
The Sidebar Component is used to make an element that overlays at the edges of the screen.
Angular PrimeNG Sidebar Properties:
- visible: It specifies the visibility of the dialog. It is of the boolean data type, the default value is false.
- position: It specifies the position of the sidebar, valid values are “left”, “right”, “bottom” and “top”. It is of string data type & the default value is left.
- fullScreen: It is used to add a close icon to the header to hide the dialog. It is of boolean data type & the default value is false.
- appendTo: It is the target element to attach the dialog, valid values are “body” or a local ng-template variable of another element. It accepts any type of data & the default value is null.
- 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.
- blockScroll: It is used to specify whether to block scrolling of the document when the sidebar is active. It is of boolean data type & the default value is false.
- baseZIndex: It is used to set the base zIndex value to use in layering. It is of number data type & the default value is 0.
- autoZIndex: It is used to specify whether to automatically manage the layering. It is of the boolean data type, and the default value is true.
- modal: It is used to specify whether an overlay mask is displayed behind the sidebar. It is of the boolean data type, and the default value is true.
- dismissible: It is used to specify whether to dismiss the sidebar at the click of the mask. It is of the boolean data type, and the default value is true.
- showCloseIcon: It is used to specify whether to display the close icon. It is of the boolean datatype, and the default value is true.
- 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).
- ariaCloseLabel: It is used to set the aria-label of the close icon. It is of string data type & the default value is close.
- closeOnEscape: It is used to specify if pressing the escape key should hide the sidebar. It is of the boolean data type, and the default value is true.
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:
To run the above file run the below command:
ng serve --save
Example 1: Below is the example code that illustrates the use of Angular PrimeNG Sidebar Properties using the position property.
- app.component.html:
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 > < h5 >Angular PrimeNG Sidebar Position Properties</ h5 > < p-sidebar [(visible)]="gfg1" styleClass = "p-sidebar-md" position = "top" > < h2 >This is a Top Sidebar!</ h2 > < p-button type = "button" (click)=" gfg1 = false " label = "OK" styleClass = "p-button-info" > </ p-button > < p-button type = "button" (click)=" gfg1 = false " label = "Cancel" styleClass = "p-button-danger p-ml-2" > </ p-button > </ p-sidebar > < p-sidebar [(visible)]="gfg2" styleClass = "p-sidebar-md" position = "bottom" > < h2 >This is a Bottom Sidebar!</ h2 > < p-button type = "button" (click)=" gfg2 = false " label = "OK" styleClass = "p-button-info" > </ p-button > < p-button type = "button" (click)=" gfg2 = false " label = "Cancel" styleClass = "p-button-danger p-ml-2" > </ p-button > </ p-sidebar > < p-button (click)=" gfg1 = true " label = "Position Top!" styleClass = "p-mr-2" > </ p-button > < p-button (click)=" gfg2 = true " label = "Position Bottom!" > </ p-button > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , styleUrls: [ './app.component.scss' ], }) export class AppComponent {} |
- app.module.ts:
Javascript
import { NgModule } from "@angular/core" ; import { BrowserModule } from "@angular/platform-browser" ; 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: Below is another example code that illustrates the use of Angular PrimeNG Sidebar Properties using the fullscreen property.
- app.component.html:
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 > < h5 >Angular PrimeNG Sidebar FullScreen Properties</ h5 > < p-sidebar [(visible)]="gfg1" [fullScreen]="true" styleClass = "p-sidebar-md" position = "top" > < h2 >This is a FullScreen Sidebar!</ h2 > < p-button type = "button" (click)=" gfg1 = false " label = "OK" styleClass = "p-button-info" > </ p-button > < p-button type = "button" (click)=" gfg1 = false " label = "Cancel" styleClass = "p-button-danger p-ml-2" > </ p-button > </ p-sidebar > < p-button (click)=" gfg1 = true " label = "FullSCreen Sidebar!" styleClass = "p-mr-2" > </ p-button > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , styleUrls: [ './app.component.scss' ], }) export class AppComponent {} |
- app.module.ts:
Javascript
import { NgModule } from "@angular/core" ; import { BrowserModule } from "@angular/platform-browser" ; 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:

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