Using Text Control in Angular Routes
This article describes how to use TX Text Control for Angular in routes by removing the previously connected singleton instance from the DOM explicitly.

TX Text Control for Angular is created as a singleton instance on a page. Therefore, the complete control must be removed explicitly from the DOM when loading a partial view a second time. In Angular, "partial views" are implemented through routes. In this sample, two routes are implemented:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { TextControlComponent } from './textcontrol/textcontrol.component';
const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'textcontrol', component: TextControlComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
The component home and textcontrol are navigated through links on the main app page:
<h1>Main View</h1>
<nav>
<a routerLink="/home" routerLinkActive="active">Home</a>
<br>
<a (click)="removeEditor()" routerLink="/textcontrol" routerLinkActive="active">
Document Editor
</a>
</nav>
<router-outlet></router-outlet>
Due to the nature of Angular routes, the page is not reloaded when clicking on the navigation links, but a partial views is loaded dynamically into the DOM.
The problem with TX Text Control in this case is, that the complete instance including connected JavaScript events is still available in the DOM and must be explicitly removed. In the above code, the (click) event is used to call the removeEditor method.
This method is declared in app.component.ts:
import { Component } from '@angular/core';
declare const removeEditorFromDom: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'TXTestApp';
removeEditor() {
removeEditorFromDom();
}
}
removeEditor calls the JavaScript function removeEditorFromDom which internally calls the remove
function removeEditorFromDom()
{
TXTextControl.removeFromDom();
}
This way, a new partial view can be loaded and reused including a Text Control editor with a new and safe connection to the WebSocketHandler.
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Angular CLI 8
Angular
Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.
Related Posts
Using the Document Editor in SPA Applications using the removeFromDom Method
This article shows how to use the removeFromDom method to remove the Document Editor from the DOM when it is no longer needed. This is useful when the Document Editor is used in a Single Page…
Observe When the Reporting Preview Tab is Active Using MutationObserver
This article shows how to observe when the Reporting Preview tab is active using MutationObserver. The Reporting Preview tab is a feature of the TX Text Control Document Editor that allows you to…
Building an ASP.NET Core Backend Application to Host the Document Editor and…
This article explains how to create an ASP.NET Core backend application to host the Document Editor and Document Viewer. This backend application is required to provide the required functionality…
Reuse Angular Document Editor Instances in Bootstrap Tabs
The initialization time of document editor instances is time-consuming and requires resources on both the server side and the client side. To reuse instances, they can be moved within the DOM.…
JavaScript: Avoid Flickering and Visual Updates by Grouping Undo Steps
The JavaScript API can be used to group several steps into one undo action that can be undone with a single undo call. Additionally, those groups are visually updated at once to avoid screen…