ng-cw-v12
Version:
Angular UI component library
85 lines (80 loc) • 3.84 kB
JavaScript
import * as i0 from '@angular/core';
import { Component, Input, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { __awaiter } from 'tslib';
class TxtViewerComponent {
constructor(eleRef) {
this.eleRef = eleRef;
this.ncUrl = '';
this.sheetNameMode = false;
}
set ncSheetName(value) {
this.sheetNameMode = value !== null && value !== undefined && value !== false && value !== 'false';
}
ngOnChanges(changes) {
if (changes['ncUrl']) {
this.renderTextDocument();
}
}
renderTextDocument() {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield fetch(this.ncUrl);
const text = yield response.text();
const container = this.eleRef.nativeElement.querySelector('#txt-container');
container.innerHTML = `<pre>${this.escapeHtml(text)}</pre>`;
}
catch (error) {
console.error('加载文本文件时出错:', error);
}
});
}
escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
}
TxtViewerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: TxtViewerComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
TxtViewerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.5", type: TxtViewerComponent, selector: "nc-txt-viewer", inputs: { ncUrl: "ncUrl", ncSheetName: "ncSheetName" }, usesOnChanges: true, ngImport: i0, template: "<div id=\"txt-container\"></div>", styles: ["#txt-container{width:100%;height:100%}\n"] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: TxtViewerComponent, decorators: [{
type: Component,
args: [{
selector: 'nc-txt-viewer',
templateUrl: './txt-viewer.component.html',
styleUrls: ['./txt-viewer.component.less']
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { ncUrl: [{
type: Input
}], ncSheetName: [{
type: Input
}] } });
class NcTxtViewerModule {
}
NcTxtViewerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: NcTxtViewerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NcTxtViewerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: NcTxtViewerModule, declarations: [TxtViewerComponent], imports: [CommonModule], exports: [TxtViewerComponent] });
NcTxtViewerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: NcTxtViewerModule, imports: [[
CommonModule
]] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0, type: NcTxtViewerModule, decorators: [{
type: NgModule,
args: [{
declarations: [
TxtViewerComponent
],
imports: [
CommonModule
],
exports: [
TxtViewerComponent
]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { NcTxtViewerModule, TxtViewerComponent };
//# sourceMappingURL=ng-cw-v12-txt-viewer.js.map