Open In App

Angular PrimeNG Splitter Component

Last Updated : 14 Feb, 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. In this article, we will know how to use the Splitter component in Angular PrimeNG. We will also learn about the properties, events & styling along with their syntaxes that will be used in the code. 

Splitter Component: It allows a user to split two-element using a splitter & utilized it separately and resize panels.

Properties:

  • panelSizes: It is used to specify the size of the. It is of number data type & the default value is null.
  • minSizes: It is used to specify the minimum size of the elements. It is of number data type & the default value is null.
  • layout: It is used to set the orientation of the panels. It is of string data type & the default value is horizontal.
  • gutterSize: It is used to specify the size of the divider in pixels. It is of number data type & the default value is 4.
  • stateKey: It is used to specify the storage identifier of a stateful Splitter. It is of string data type & the default value is null.
  • stateStorage: It is used to define where a stateful splitter keeps its state. It is of string data type & the default value is session.
  • style: It is used to specify the inline style of the component. It is of object data type & the default value is null.
  • styleClass: It is used to specify the style class of the component. It is of string data type & the default value is null.
  • panelStyleClass: It is used to specify the style class of the panel. It is of string data type & the default value is null.
  • panelStyle: It is used to specify the inline style of the panel. It is of object data type & the default value is null.

Event: 

  • onResizeStart: It is a callback that is fired when resizing starts.
  • onResizeEnd: It is a callback that is fired when resizing end.

 

Styling:

  • p-splitter: It is the container element.
  • p-splitter: It is the container element during resize.
  • p-splitter-horizontal: It is the container element with a horizontal layout.
  • p-splitter-vertical: It is the container element with the vertical layout.
  • p-splitter-panel: It is the splitter panel element.
  • p-splitter-gutter: It is the gutter element to use when resizing the panels.
  • p-splitter-gutter-handle: It is the handle element of the gutter.

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:

Example 1: This is the basic example that illustrates how to use the Splitter component.

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Splitter Component</h5>
<p-splitter>
  <ng-template pTemplate>
    <div class="p-col p-ai-center p-jc-center">
      Angular PrimeNG is a framework used with angular 
      to create components with great styling and this 
      framework is very easy to use and is used to make
      responsive websites.
    </div>
  </ng-template>
  <ng-template pTemplate>
    <div class="p-col p-ai-center p-jc-center">
      Angular PrimeNG is a framework used with angular 
      to create components with great styling and this 
      framework is very easy to use and is used to make
      responsive websites.
    </div>
  </ng-template>
</p-splitter>


app.component.ts




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {}


 

app.module.ts




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


Output:

Example 2: In this example, we will know how to use the layout property in the splitter component.

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Splitter Component</h5>
<p-splitter layout="vertical">
  <ng-template pTemplate>
    <div class="p-col p-ai-center p-jc-center">
      Angular PrimeNG is a framework used with angular 
      to create components with great styling and this 
      framework is very easy to use and is used to make
      responsive websites.
    </div>
  </ng-template>
  <ng-template pTemplate>
    <div class="p-col p-ai-center p-jc-center">
      Angular PrimeNG is a framework used with angular 
      to create components with great styling and this 
      framework is very easy to use and is used to make
      responsive websites.
    </div>
  </ng-template>
</p-splitter>


app.component.ts




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {}


app.module.ts




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


Output:

Reference: https://primeng.org/splitter



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads