---
title: Page Break and Page Merge
product: Survey Creator
description: Learn how to implement and use the page break and page merge features in Survey Creator to efficiently structure multi-page surveys. This JavaScript demo shows how survey authors can split a page into two or merge consecutive pages with just a few clicks.
framework: Angular
source: https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/angular
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Page Break and Page Merge (Angular)

Page breaks and page merge features help survey authors manage the survey structure more quickly and efficiently. Use a page break to split a single survey page into two: simply drag the Page Break item from the Toolbox and drop it between two elements on the design surface. Conversely, the page merge option lets you combine two consecutive pages into one. To merge, select Page 2 or any subsequent page on the design surface and click the "Merge with previous page" button at the top of that page. The elements from the selected page will be appended to the previous one.

To implement the page breaks and page merge functionalities to Survey Creator, follow the steps below:

1. Create a custom `PageBreak` class.           
Extend the `Question` class and override the `getType()` method.

2. Register icons for the Page Break toolbox item and Page Merge action button.         
Define SVG icons as string values and use the `SvgRegistry.registerIcon(name, svg)` method to register them.

3. Handle the [`onDragDropAllow`](/survey-creator/documentation/api-reference/survey-creator#onDragDropAllow) and [`onQuestionAdded`](/survey-creator/documentation/api-reference/survey-creator#onQuestionAdded) events.           
These events allow you to manage acceptable drop positions and split a page when users drag the Page Break item from the Toolbox onto the design surface.

4. Add the Page Break toolbox item.         
Pass an [`IQuestionToolboxItem`](/survey-creator/documentation/api-reference/iquestiontoolboxitem) object to the Toolbox's [`addItem`](/survey-creator/documentation/api-reference/questiontoolbox#addItem) method. Within this object, define the item's name and title, assign one of the icons registered on step 2, and specify a JSON object that this item produces.

5. Add the Page Merge action button.        
Handle the [`onElementGetActions`](/survey-creator/documentation/api-reference/survey-creator#onElementGetActions) event using a function. Within it, create and configure an [`IAction`](/form-library/documentation/api-reference/iaction) object by specifying its ID, title, icon, visibility rules, and a function to execute when users click this button. Add the `IAction` object to the `options.actions` array.

Refer to the Code tab to view the full code listing.

## Files

### `src/app/components/creator.component.css`

```css
/* You can define custom CSS rules here */
```

### `src/app/components/creator.component.html`

```html
<div style="position: fixed; top: 0; bottom: 0; right: 0; left: 0;">
    <survey-creator [model]="model"></survey-creator>
</div>
```

### `src/app/components/icons.js`

```js
export const pageBreakToolboxIcon = `<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M20.75 16V19C20.75 20.52 19.52 21.75 18 21.75H6C4.48 21.75 3.25 20.52 3.25 19V16C3.25 15.59 3.59 15.25 4 15.25C4.41 15.25 4.75 15.59 4.75 16V19C4.75 19.69 5.31 20.25 6 20.25H18C18.69 20.25 19.25 19.69 19.25 19V16C19.25 15.59 19.59 15.25 20 15.25C20.41 15.25 20.75 15.59 20.75 16ZM18 2.25H6C4.48 2.25 3.25 3.48 3.25 5V8C3.25 8.41 3.59 8.75 4 8.75C4.41 8.75 4.75 8.41 4.75 8V5C4.75 4.31 5.31 3.75 6 3.75H18C18.69 3.75 19.25 4.31 19.25 5V8C19.25 8.41 19.59 8.75 20 8.75C20.41 8.75 20.75 8.41 20.75 8V5C20.75 3.48 19.52 2.25 18 2.25ZM4 12.75H5C5.41 12.75 5.75 12.41 5.75 12C5.75 11.59 5.41 11.25 5 11.25H4C3.59 11.25 3.25 11.59 3.25 12C3.25 12.41 3.59 12.75 4 12.75ZM20 11.25H19C18.59 11.25 18.25 11.59 18.25 12C18.25 12.41 18.59 12.75 19 12.75H20C20.41 12.75 20.75 12.41 20.75 12C20.75 11.59 20.41 11.25 20 11.25ZM10 12.75C10.41 12.75 10.75 12.41 10.75 12C10.75 11.59 10.41 11.25 10 11.25H9C8.59 11.25 8.25 11.59 8.25 12C8.25 12.41 8.59 12.75 9 12.75H10ZM15 12.75C15.41 12.75 15.75 12.41 15.75 12C15.75 11.59 15.41 11.25 15 11.25H14C13.59 11.25 13.25 11.59 13.25 12C13.25 12.41 13.59 12.75 14 12.75H15Z" /></svg>`;

export const pageMergeActionIcon = `<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<path d="M8.5 5.75V7H9.75C10.16 7 10.5 7.34 10.5 7.75C10.5 8.16 10.16 8.5 9.75 8.5H8.5V9.75C8.5 10.16 8.16 10.5 7.75 10.5C7.34 10.5 7 10.16 7 9.75V8.5H5.75C5.34 8.5 5 8.16 5 7.75C5 7.34 5.34 7 5.75 7H7V5.75C7 5.34 7.34 5 7.75 5C8.16 5 8.5 5.34 8.5 5.75ZM12.75 1H2.75C1.79 1 1 1.79 1 2.75V5.75C1 6.16 1.34 6.5 1.75 6.5C2.16 6.5 2.5 6.16 2.5 5.75V2.75C2.5 2.61 2.61 2.5 2.75 2.5H12.75C12.89 2.5 13 2.61 13 2.75V5.75C13 6.16 13.34 6.5 13.75 6.5C14.16 6.5 14.5 6.16 14.5 5.75V2.75C14.5 1.79 13.71 1 12.75 1ZM13.75 9C13.34 9 13 9.34 13 9.75V12.75C13 12.89 12.89 13 12.75 13H2.75C2.61 13 2.5 12.89 2.5 12.75V9.75C2.5 9.34 2.16 9 1.75 9C1.34 9 1 9.34 1 9.75V12.75C1 13.71 1.79 14.5 2.75 14.5H12.75C13.71 14.5 14.5 13.71 14.5 12.75V9.75C14.5 9.34 14.16 9 13.75 9Z" /></svg>`;
```

### `src/app/components/survey-json.js`

```js
export const surveyJson = {
  "pages": [{
    "name": "page1",
    "elements": [{
      "type": "text",
      "name": "question1"
    }, {
      "type": "text",
      "name": "question2"
    }]
  }, {
    "name": "page2",
    "elements": [{
      "type": "text",
      "name": "question3"
    }]
  }]
}
```

### `src/app/components/creator.component.ts`

```ts
import { Component, OnInit } from "@angular/core";
import { SurveyCreatorModel } from "survey-creator-core";
import "survey-core/survey.i18n";
import "survey-creator-core/survey-creator-core.i18n";
import { Question, Serializer, Action, ComputedUpdater, SvgRegistry, IElement, PageModel } from "survey-core";
import { pageBreakToolboxIcon, pageMergeActionIcon } from "./icons";
import { surveyJson } from "./survey-json";
import { SurveyHelper } from "survey-creator-core";
import "survey-core/survey-core.css";
import "survey-creator-core/survey-creator-core.css";

import SurveyTheme from "survey-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SurveyTheme); // Add predefined Survey Creator UI themes

const PageBreakType = "pagebreak";

class PageBreak extends Question {
    getType() {
        return PageBreakType;
    }
}

Serializer.addClass(PageBreakType, [], () => new PageBreak(""), "question");
SvgRegistry.registerIcon("icon-toolbox-pagebreak", pageBreakToolboxIcon);
SvgRegistry.registerIcon("icon-action-pagemerge", pageMergeActionIcon);

function isPageBreak(el) {
    return el ? el.getType() === PageBreakType : false;
}

function moveElementsToPage(page, elements) {
    elements.forEach((el) => {
        el.parent.removeElement(el);
        page.addElement(el);
    });
}
@Component({
    // tslint:disable-next-line:component-selector
    selector: "component-survey-creator",
    templateUrl: "./creator.component.html",
    styleUrls: ["./creator.component.css"]
})
export class SurveyCreatorComponent implements OnInit {
    model: SurveyCreatorModel;
    ngOnInit() {
        const creator = new SurveyCreatorModel();
        // Do not allow placing a page break within a panel and at the beginning or end of a page
        creator.onDragDropAllow.add((_, options) => {
            const q = options.draggedElement;
            if (isPageBreak(q)) {
                const el = options.toElement as PageModel;
                options.allow = !!el && !el.isPanel && (!el.parent || el.parent.isPage);
                if (el.isPage && el.elements.length < 2) {
                    options.allow = false;
                }
                if (options.allow && el.page) {
                    const page = el.page;
                    const elements = page.elements;
                    if (
                        options.insertBefore &&
                        elements.indexOf(options.insertBefore) === 0
                    ) {
                        options.allow = false;
                    }
                    if (
                        options.insertAfter &&
                        elements.indexOf(options.insertAfter) === elements.length - 1
                    ) {
                        options.allow = false;
                    }
                }
            }
        });
        
        // Create a new page and move questions to it if the added element is a page break 
        creator.onQuestionAdded.add((_, options) => {
            const q = options.question;
            if (isPageBreak(q)) {
                const curPage = q.page as PageModel;
                const index = curPage.indexOf(q);
                q.delete();
                const elements = [] as IElement[];
                for (let i = index; i < curPage.elements.length; i++) {
                    elements.push(curPage.elements[i]);
                }
                const survey = creator.survey;
                const newPageName = SurveyHelper.getNewPageName(survey.pages);
                const newPageIndex = survey.pages.indexOf(curPage) + 1;
                const newPage = survey.addNewPage(newPageName, newPageIndex);
                moveElementsToPage(newPage, elements);
                creator.selectElement(newPage);
            }
        });
        
        // Add a page action that merges a page with the previous one
        creator.onElementGetActions.add((_, options) => {
            const page = options.element as PageModel;
            if (page.isPage) {
                const action = new Action({
                    id: "page_merge",
                    visible: new ComputedUpdater(() => page.visibleIndex > 0),
                    title: "Merge with previous page",
                    iconName: "icon-action-pagemerge",
                    iconSize: 16,
                    action: () => {
                        const pages = creator.survey.pages;
                        const index = pages.indexOf(page);
                        if (index >= 1) {
                            creator.startUndoRedoTransaction("merge page");
                            moveElementsToPage(
                                pages[index - 1],
                                ([] as IElement[]).concat(page.elements)
                            );
                            page.delete();
                            creator.stopUndoRedoTransaction();
                        }
                    }
                });
                options.actions.push(action);
            }
        });
        
        // Add a Page Break toolbox item
        creator.toolbox.addItem({
            name: "page_break",
            title: "Page Break",
            iconName: "icon-toolbox-pagebreak",
            showInToolboxOnly: true,
            json: { type: PageBreakType }
        }, 0);
        
        creator.toolbox.forceCompact = false;
        creator.showSurveyHeader = false;
        creator.JSON = surveyJson;
        this.model = creator;
    }
}
```

### `src/app/app.component.html`

```html
<component-survey-creator></component-survey-creator>
```

### `src/app/app.component.ts`

```ts
import { Component } from "@angular/core";

@Component({
    selector: "app-root",
    templateUrl: "./app.component.html"
})
export class AppComponent {
    title = "CodeSandbox";
}
```

### `src/app/app.module.ts`

```ts
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import { SurveyCreatorModule } from "survey-creator-angular";
import { SurveyCreatorComponent } from "./components/creator.component";

@NgModule({
    declarations: [AppComponent, SurveyCreatorComponent],
    imports: [BrowserModule, SurveyCreatorModule],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }
```

### `src/environments/environment.prod.ts`

```ts
export const environment = {
    production: true
};
```

### `src/environments/environment.ts`

```ts
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
    production: false
};
```

### `src/index.html`

```html
<app-root></app-root>
```

### `src/main.ts`

```ts
import { enableProdMode } from "@angular/core";
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";

import { AppModule } from "./app/app.module";
import { environment } from "./environments/environment";

if (environment.production) {
    enableProdMode();
}

platformBrowserDynamic()
    .bootstrapModule(AppModule)
    .catch(err => console.log(err));
```

### `src/polyfills.ts`

```ts
/**
 * This file includes polyfills needed by Angular and is loaded before the app.
 * You can add your own extra polyfills to this file.
 *
 * This file is divided into 2 sections:
 *   1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
 *   2. Application imports. Files imported after ZoneJS that should be loaded before your main
 *      file.
 *
 * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
 * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
 * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
 *
 * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
 */

/***************************************************************************************************
 * BROWSER POLYFILLS
 */

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
// import 'core-js/es6/symbol';
// import 'core-js/es6/object';
// import 'core-js/es6/function';
// import 'core-js/es6/parse-int';
// import 'core-js/es6/parse-float';
// import 'core-js/es6/number';
// import 'core-js/es6/math';
// import 'core-js/es6/string';
// import 'core-js/es6/date';
// import 'core-js/es6/array';
// import 'core-js/es6/regexp';
// import 'core-js/es6/map';
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js';  // Run `npm install classlist.js`.

/** IE10 and IE11 requires the following for the Reflect API. */
// import 'core-js/es6/reflect';

/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import "core-js/proposals/reflect-metadata";

/**
 * Required to support Web Animations `@angular/platform-browser/animations`.
 * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
 **/
// import 'web-animations-js';  // Run `npm install web-animations-js`.

/***************************************************************************************************
 * Zone JS is required by default for Angular itself.
 */
import "zone.js/dist/zone"; // Included with Angular CLI.

/***************************************************************************************************
 * APPLICATION IMPORTS
 */
```

### `src/styles.css`

```css
/* You can add global styles to this file and import other style files */
```

### `src/typings.d.ts`

```ts
/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
    id: string;
}
```

### `.angular-cli.json`

```json
{
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [ "assets", "favicon.ico" ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "prefix": "app",
      "styles": [ "styles.css"  ],
      "scripts": [  ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ]
}
```

### `_tsconfig.json`

```json
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "allowSyntheticDefaultImports": true,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "resolveJsonModule": true,
    "target": "es2015",
    "module": "es2020",
    "lib": [
      "es2018",
      "dom"
    ]
  }
}
```

### `package.json`

```json
{
  "name": "surveyjs-angular",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "14.1.1",
    "@angular/cdk": "14.1.1",
    "@angular/common": "14.1.1",
    "@angular/compiler": "14.1.1",
    "@angular/core": "14.1.1",
    "@angular/forms": "14.1.1",
    "@angular/platform-browser": "14.1.1",
    "@angular/platform-browser-dynamic": "14.1.1",
    "@angular/router": "14.1.1",
    "core-js": "3.6.4",
    "rxjs": "6.5.4",
    "survey-angular-ui": "latest",
    "survey-creator-core": "latest",
    "survey-core": "latest",
    "survey-creator-angular": "latest",
    "tslib": "1.13.0",
    "zone.js": "0.11.7"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.0.0",
    "@angular/cli": "~13.0.0",
    "@types/jasmine": "3.6.3",
    "@types/jasminewd2": "2.0.8",
    "@types/node": "14.14.28",
    "codelyzer": "6.0.1",
    "jasmine-core": "3.6.0",
    "jasmine-spec-reporter": "6.0.0",
    "karma": "6.1.1",
    "karma-chrome-launcher": "3.1.0",
    "karma-coverage-istanbul-reporter": "3.0.3",
    "karma-jasmine": "4.0.1",
    "karma-jasmine-html-reporter": "1.5.4",
    "protractor": "7.0.0",
    "ts-node": "9.1.1",
    "tslint": "~6.1.3",
    "typescript": "4.1.5"
  },
  "keywords": [ "angular", "surveyjs" ],
  "description": "SurveyJS-Angular example project"
}
```

## Other Frameworks

- [React](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/reactjs.md)
- [Vue 3](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/vue3js.md)
- [jQuery](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/jquery.md)
- [Vanilla JS](https://surveyjs.io/survey-creator/examples/page-break-and-page-merge/vanillajs.md)
