angular - 如何以 Angular 8 显示文件

标签 angular file viewer

我想在 Angular 组件中显示具有不同扩展名的文件。
我为此使用哪些模块?
我已经查看了以下模块。但每个模块都有问题。

  • ngx-doc-查看器:https://www.npmjs.com/package/ngx-doc-viewer
  • ngx-extended-pdf-viewer:https://www.npmjs.com/package/ngx-extended-pdf-viewer
  • 网络浏览器:https://www.pdftron.com/webviewer/demo/
  • 最佳答案

    您可以使用 Angular 文件查看器
    此包支持 PDF、JPEG、PNG、MP4
    Demo
    安装

    npm i @taldor-ltd/angular-file-viewer ng2-pdf-viewer
    
    用法
    将 AngularFileViewerModule 添加到模块的导入中
    import { NgModule } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    
    import { AngularFileViewerModule } from '@taldor-ltd/angular-file-viewer';
    
    import { AppComponent } from './app/app.component';
    
     @NgModule({
      imports: [BrowserModule, AngularFileViewerModule],
     declarations: [AppComponent],
     bootstrap: [AppComponent]
     })
    
     class AppModule {}
    
    platformBrowserDynamic().bootstrapModule(AppModule);
    
    然后在你的组件中使用它
    (PDF 样本)
    import { Component } from '@angular/core';
    
    import { FileMimeType } from '@taldor-ltd/angular-file-viewer';
    
    @Component({
    selector: 'app-root',
    template: `
    <tld-file-viewer [src]="src" [type]="type"></tld-file-viewer>`
    
    })
    export class AppComponent {
    src = 'http://www.africau.edu/images/default/sample.pdf';
     type = FileMimeType.PDF;
    }
    
    documentation

    关于angular - 如何以 Angular 8 显示文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60734926/

    相关文章:

    javascript - 如何检查数据是否完整加载以使用异步管道Angular 8

    python - 将实时输出保存到 python 中的文件中

    c# - 如何读取多个文本文件并将其保存到一个文本文件中?

    http - 上传文件的大小

    html - CSS - float 不应用任何效果

    angular - 如何在 typescript 中导入 Markdown (.md)文件

    .net - "Help System"用于基于 .NET 2010、C# 和 WPF 的桌面应用程序

    Delphi 线条彩色文本组件替换 TRichEdit 以提高性能

    java - PDF 专用文件浏览器

    Angular:如何在 PrimeNG p-steps 组件中设置已完成步骤的样式?