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 to save a document.

You learned how to use the TX Text Control document editor to create your first Angular application in a previous tutorial. This tutorial will show you how to use the JavaScript API to load a document from a URL and how to save a document within an Angular application.
Prerequisites
This tutorial is based on the basic Angular application created in the first step-by-step tutorial.
Learn More
This article shows how to use the TX Text Control Document Editor npm package for Angular within an Angular CLI application. This is the first course of a getting started series for Angular to learn how to use the Document Editor in Angular.
Creating the Application
-
Open the Angular application created in the previous tutorial in your preferred editor such as Visual Studio Code.
-
Create a folder named js in the folder src/assets/ and create a new JavaScript file named tx.js. Paste the following into the newly created file:
async function saveDocument(StreamType) { // save document return new Promise((resolve, reject) => { TXTextControl.saveDocument(StreamType, function (e) { if (e) { resolve(e.data); } else { reject('Error saving document'); } }); }); } function loadDocumentFromUrl(url) { // download document using xml http request var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'blob'; xhr.onload = function () { if (xhr.status === 200) { var blob = xhr.response; var reader = new FileReader(); reader.onload = function () { // get the base64 encoded string var base64 = reader.result.split(',')[1]; // load the document TXTextControl.loadDocument(TXTextControl.StreamType.InternalUnicodeFormat, base64); }; reader.readAsDataURL(blob); } }; xhr.send(); }
-
Add this JavaScript file to the scripts array of the projects architect/build/options element in the angular.json file:
"scripts": [ "src/assets/js/custom.js" ]
-
Add the declaration and onClickSave and onClickLoad methods to the app.component.ts TypeScript file, so that the complete file looks like this:
import { Component } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterOutlet } from '@angular/router'; import { DocumentEditorModule } from '@txtextcontrol/tx-ng-document-editor'; declare const saveDocument: any; declare const loadDocumentFromUrl: any; declare const TXTextControl: any; @Component({ selector: 'app-root', standalone: true, imports: [CommonModule, RouterOutlet, DocumentEditorModule], templateUrl: './app.component.html', styleUrl: './app.component.css' }) export class AppComponent { async onClickSave() { var base64Document = await saveDocument(TXTextControl.StreamType.InternalUnicodeFormat); console.log(base64Document); } onClickLoad() { loadDocumentFromUrl("http://yourdomain/getDocument?filename=demo.tx"); } }
The URL specified in the loadDocumentFromUrl method in this example should be replaced with your endpoint, which will return any supported document as a file.
-
Finally, add two buttons to the app.component.html using the Angular click handlers:
<tx-document-editor width="1000px" height="500px" webSocketURL="wss://backend.textcontrol.com/TXWebSocket?access-token=yourtoken"> </tx-document-editor> <div> <button (click)="onClickLoad()" class="btn btn-primary">Load Document</button> <button (click)="onClickSave()" class="btn btn-primary">Save Document</button> </div>
Starting the Application
After launching this application, the Load Document button loads a document from a URL. When you click the Save Document button, the document is saved in the internal TX Text Control format and written to the console as a base64-encoded string for demonstration purposes.
Jump to the other posts in this series:
- Getting Started: Document Editor with Angular CLI
- Getting Started: Loading and Saving Documents using Angular
- Getting Started: Programming the Angular Document Editor using JavaScript
- Getting Started: Angular Document Editor Attributes Explained
Angular
Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.
Related Posts
Reuse Persistent Document Editor Components in Angular SPA Applications
An Angular Single Page Application (SPA) dynamically updates the web page without reloading by loading all necessary resources once. This article demonstrates how to reuse persistent Document…
Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor…
This article shows how to create a backend for the Document Editor and Viewer using ASP.NET Core. The backend can be hosted on Windows and Linux and can be used in Blazor, Angular, JavaScript, and…
AngularJavaScriptDocument Editor
Getting Started: Document Editor Version 33.0 with Angular CLI 19.0
This article shows how to use the TX Text Control Document Editor version 33.0 npm package for Angular within an Angular CLI 19.0 application. It uses the trial backend running on our servers, but…
AngularASP.NET CoreDocument Editor
Changing the Language in the Angular Document Editor Using the Resource Kit
This article walks you through the process of building a satellite assembly using the Resource Kit to customize the language of the TX Text Control interface in the Angular Document Editor.
Customizing the Ribbon in TX Text Control for Angular
This post will guide you through the process of customizing the ribbon by changing its colors, adding new groups with custom buttons using Angular HttpClient to dynamically load HTML content, and…