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.
The following section explains the steps required to create and configure basic angular-cli application.
To get started with Syncfusion Angular UI Components, make sure that you have compatible versions of Angular and TypeScript.
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
ng new syncfusion-angular-app
Once you have executed the above command you may ask for following options,
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
Syncfusion packages are distributed in npm as @syncfusion
scoped packages. You can get all the Angular Syncfusion package from npm link.
Add Syncfusion Angular Layouts package to use Splitter component in your application. By using following Command you can add required packages,
npm install @syncfusion/ej2-angular-layouts --save
(or)
npm i @syncfusion/ej2-angular-layouts --save
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 { }
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;
}
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.
You can load the pane contents either as HTML element or string type using content property.
The below example shows how to load the content to panes by using ng-template
.
For detailed information, refer to the Pane Content section.
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<div id='container'>
<ejs-splitter #horizontal height='250px' width='550px'>
<e-panes>
<e-pane>
<ng-template #content>
<div class="content">
<h3 class="h3">HTML</h3>
<div class="code-preview">
<<span>!DOCTYPE html></span>
<div><<span>html></span></div>
<div><<span>body></span></div>
<<span>div</span> id="custom-image">
<div style="margin-left: 5px"><<span>img</span> src="src/albert.png"></div>
<div><<span>div</span>></div>
<div><<span>/body></span></div>
<div><<span>/html></span></div>
</div>
</div>
</ng-template>
</e-pane>
<e-pane>
<ng-template #content>
<div class="content">
<h3 class="h3">CSS</h3>
<div class="code-preview">
<span>img {{ '{' }}</span>
<div id="code-text">margin:<span>0 auto;</span></div>
<div id="code-text">display:<span>flex;</span></div>
<div id="code-text">height:<span>70px;</span></div>
<span>{{ '}' }}</span>
</div>
</div>
</ng-template>
</e-pane>
<e-pane>
<ng-template #content>
<div class="content">
<h3 class="h3">JavaScript</h3>
<div class="code-preview">
<span>var</span> image = document.getElementById("custom-image");
<div>image.addEventListener("click", function() {{ '{' }}</div>
<div style="padding-left: 20px;">// Code block for click action</div>
<span> {{ '}'}} </span>
</div>
</div>
</ng-template>
</e-pane>
</e-panes>
</ejs-splitter>
</div>`
})
export class AppComponent {
constructor() {
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { SplitterModule } from '@syncfusion/ej2-angular-layouts';
/**
* Module
*/
@NgModule({
imports: [
BrowserModule, FormsModule, SplitterModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {
}
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Angular Splitter</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Angular Splitter Component" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.1.57/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.1.57/ej2-layouts/styles/material.css" rel="stylesheet" />
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.9.0/zone.min.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='ang_container'>
<div class='wrap'>
<app-root>
<div id='loader'>LOADING....</div>
</app-root>
</div>
</div>
</body>
</html>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#code-text {
margin-left: 5px;
}
.code-preview {
margin-top: 15px;
font-size: 12px;
}
.h3 {
font-size: 14px;
margin: 4px;
}
.content {
padding: 12px;
}
.splitter-image {
margin: 0 auto;
display: flex;
height: 115px;
margin-top: 10px;
}
#container {
margin: 30px;
}
#load-content-container {
margin: 60px auto;
}
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 { Component } from '@angular/core';
@Component({
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 { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { SplitterModule } from '@syncfusion/ej2-angular-layouts';
/**
* Module
*/
@NgModule({
imports: [
BrowserModule, FormsModule, SplitterModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {
}
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Angular Splitter</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Angular Splitter Component" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.1.57/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/20.1.57/ej2-layouts/styles/material.css" rel="stylesheet" />
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zone.js/0.9.0/zone.min.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='ang_container'>
<div class='wrap'>
<app-root>
<div id='loader'>LOADING....</div>
</app-root>
</div>
</div>
</body>
</html>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#container {
margin: 50px auto;
}