Angular 2 how to display .pdf file

后端 未结 9 521
不知归路
不知归路 2020-12-18 18:01

I have an angular2 app, where I want the user to be able to download and open a pdf file in the browser.

Is there an angular2 module or component that I can use?

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 18:43

    Have you taken a look at this module https://www.npmjs.com/package/ng2-pdf-viewer?

    remember to declare it in the module like so

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms'; 
    import { HttpModule } from '@angular/http';
    
    import { PdfViewerComponent } from 'ng2-pdf-viewer'; 
    import { AppComponent } from './app.component';
    
    @NgModule({
      declarations: [
        AppComponent,
        PdfViewerComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        HttpModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

提交回复
热议问题