Products Technologies Demo Docs Blog Support Company

Angular: Loading Documents on Initializing TX Text Control

With the latest version 28.3.0, the Angular document editor received a new event that is fired when TXTextControl is available. This event can be used to access the object and to attach additional events.

Angular: Loading Documents on Initializing TX Text Control

The Angular version of the TX Text Control editor is loading asynchronously when added to an HTML view. That implies that the TXTextControl JavaScript object is not immediately available. An event cannot be attached to this object directly as the object doesn't exist on initializing the app.

The txDocumentEditorLoaded Event

With the latest version 28.3.0, the Angular document editor received a new event that is fired when TXTextControl is available.

After this event is fired, the object TXTextControl exists in the DOM and can be used. In the following code, the event is used to attach the textControlLoaded event that is fired, if TX Text Control is ready to be used.

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

declare const TXTextControl: any;
declare const loadDocument: any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  
  // attach the txDocumentEditorLoaded event in the @HostListener decorator
  // https://angular.io/api/core/HostListener

  @HostListener('document:txDocumentEditorLoaded', ['$event'])
  onTxDocumentEditorLoaded() {
    
    // wait until TXTextControl has been loaded
    TXTextControl.addEventListener("textControlLoaded", function() {
      loadDocument("<strong>Hey! It compiles! Ship it!</strong>");
    });
  }
  
 }

In this event handler, the document is finally loaded using the following JavaScript function loadDocument:

function loadDocument(html) {
    TXTextControl.loadDocument(TXTextControl.streamType.HTMLFormat, btoa(html));
}

This new event helps to interact with TX Text Control on initializing the app which is very helpful when TX Text Control should be initialized with a loaded document on loading the app.

Test this on your own by creating a trial access token. No download required to evaluate TX Text Control for Angular.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • Javascript: TXTextControl.loadDocument Method
  • Javascript: TXTextControl Object

Angular

Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.

Learn more about Angular

Related Posts

AngularEventsLoading

Angular: Loading Excerpt JSON Data on Initializing TX Text Control

Data excerpt files are used to provide the data structure that is used to fill the merge field drop-down lists. This article shows how to load JSON data into the Angular editor.


AngularASP.NET CoreDocument Viewer

Asynchronous Loading and Saving in Angular Document Editor with an ASP.NET…

This article shows how to load and save documents in an Angular Document Editor using an ASP.NET Core Web API asynchronously. A Web API is used to load and save documents from and to the server…


AngularDocument EditorLoading

Getting Started: Loading and Saving Documents using Angular

This article shows how to load and save documents using the Angular Document Editor. It explains how to use the Angular Document Editor in an Angular application and how to load from a URL and how…


AngularDocument SigningLoading

Signing Documents with the Angular DocumentViewer

The TX Text Control DocumentViewer for Angular can be used to request signatures for an electronic document signing process. This tutorial shows how to request a signature.


AngularASP.NETJavaScript

TXTextControl.Web: Creating a Custom ButtonBar using the InputFormat Class

TX Text Control X18 implements the InputFormat class in the JavaScript API that enables developers to build custom button bars.