Getting started with Angular Splitter component

25 Jul 20246 minutes to read

The following section explains the steps required to create the Syncfusion’s Angular Splitter component.
The Splitter component will make splittable layouts by placing separator in-between two panes. Based on the position of the separator you can adjust size of the splitter panes in the dynamic manner.

To get start quickly with Angular Splitter using CLI and Schematics, you can check on this video:

Getting Started with Angular CLI

The following section explains the steps required to create and configure basic angular-cli application.

Prerequisites

To get started with Syncfusion Angular UI Components, make sure that you have compatible versions of Angular and TypeScript.

  • Angular : 6+
  • TypeScript : 2.6+

Setting up an Angular project

Angular provides an easiest way to setup project using Angular CLI Angular CLI tool.

Install the CLI application globally in your machine.

  npm install -g @angular/cli

Create a new application

  ng new syncfusion-angular-app

Once you have executed the above command you may ask for following options,

  • Would you like to add Angular routing?
  • Which stylesheet format would you like to use?

By default, it install the CSS style base application. To setup with SCSS, pass –style=SCSS argument on create project.

Example code snippet.

  ng new syncfusion-angular-app --style=SCSS

Navigate to the created project folder.

  cd syncfusion-angular-app

Installing Syncfusion Splitter package

Syncfusion packages are distributed in npm as @syncfusion scoped packages. You can get all the Angular Syncfusion package from npm link.

Currently, Syncfusion provides two types of package structures for Angular components,

  1. Ivy library distribution package format
  2. Angular compatibility compiler(Angular’s legacy compilation and rendering pipeline) package.

Ivy library distribution package

Syncfusion Angular packages(>=20.2.36) has been moved to the Ivy distribution to support the Angular Ivy rendering engine and the package are compatible with Angular version 12 and above. To download the package use the below command.

Add @syncfusion/ej2-angular-layouts package to the application.

npm install @syncfusion/ej2-angular-layouts --save

Angular compatibility compiled package(ngcc)

For Angular version below 12, you can use the legacy (ngcc) package of the Syncfusion Angular components. To download the ngcc package use the below.

Add @syncfusion/ej2-angular-layouts@ngcc package to the application.

npm install @syncfusion/ej2-angular-layouts@ngcc --save

To mention the ngcc package in the package.json file, add the suffix -ngcc with the package version as below.

@syncfusion/ej2-angular-layouts:"20.2.38-ngcc"

Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning.

Adding Splitter module

Once you have successfully installed the layouts package, corresponding component modules are ready to configure in your application from the installed location. Syncfusion Angular package provides two different types of ngModules.

Refer to Ng-Module to learn about ngModules.

Refer to the following snippet to import the SplitterModule in app.module.ts from the @syncfusion/ej2-angular-layouts.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
// Imported syncfusion SplitterModule from layouts package
import { SplitterModule } from '@syncfusion/ej2-angular-layouts';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    // Registering EJ2 Splitter Module
    SplitterModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Adding Splitter component

Add the Splitter component snippet in app.component.ts as follows.

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <div id='container'>
      <ejs-splitter #horizontal height='110px' width='100%' >
          <e-panes>
            <e-pane></e-pane>
            <e-pane></e-pane>
          </e-panes>
      </ejs-splitter>
    </div>`
})
export class AppComponent {
    constructor() {
    }
}

Add following styles in corresponding css file. The below example contains styles in styles.css file,

#container {
  margin: 50px auto;
}

Adding CSS reference

The following CSS files are available in ../node_modules/@syncfusion package folder. This can be referenced in [src/styles.css] using following code.

      @import '../node_modules/@syncfusion/ej2-base/styles/material.css';
      @import '../node_modules/@syncfusion/ej2-icons/styles/material.css';
      @import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
      @import '../node_modules/@syncfusion/ej2-angular-layouts/styles/material.css';

The Custom Resource Generator (CRG) is an online web tool, which can be used to generate the custom script and styles for a set of specific components.
This web tool is useful to combine the required component scripts and styles in a single file.

Load content to the pane

You can load the pane contents either as HTML element or string type using content property.

For detailed information, refer to the Pane Content section.

Running the application

Run the ng serve command in command window, it will serve your application and you can open the browser window. Output will appear as follows.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { SplitterModule } from '@syncfusion/ej2-angular-layouts'




import { Component } from '@angular/core';

@Component({
imports: [
         FormsModule, SplitterModule
    ],


standalone: true,
    selector: 'app-root',
    template: `
    <div id='container'>
          <ejs-splitter #horizontal height='250px' width='600px'>
            <e-panes>
                <e-pane></e-pane>
                <e-pane></e-pane>
                <e-pane></e-pane>
            </e-panes>
          </ejs-splitter>
    </div>`
})
export class AppComponent {
    constructor() {
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

See Also