-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathapp.component.ts
More file actions
33 lines (28 loc) · 882 Bytes
/
app.component.ts
File metadata and controls
33 lines (28 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Component, ElementRef, ViewChild, OnDestroy } from '@angular/core';
import { SuperDoc } from 'superdoc';
@Component({
selector: 'app-root',
template: `
<div style="padding: 1rem; background: #f5f5f5">
<input type="file" accept=".docx" (change)="onFileChange($event)" />
</div>
<div #editor style="height: calc(100vh - 60px)"></div>
`,
})
export class AppComponent implements OnDestroy {
@ViewChild('editor', { static: true }) editorRef!: ElementRef;
private superdoc: SuperDoc | null = null;
onFileChange(event: Event) {
const file = (event.target as HTMLInputElement).files?.[0];
if (!file) return;
this.superdoc?.destroy();
this.superdoc = new SuperDoc({
selector: this.editorRef.nativeElement,
documentMode: 'editing',
document: file,
});
}
ngOnDestroy() {
this.superdoc?.destroy();
}
}