angular - Embed pdf in Angular2 component -


in angular 4.3 want open modal popup , show embedded pdf file, shown here: https://pdfobject.com/static.html

i used modal popup component answer pops nicely. test html modal looks this:

<a class="btn btn-default" (click)="setcontent();modal.show()">show</a> <app-modal #modal>   <div class="app-modal-header">     testing pdf embedding   </div>   <div class="app-modal-body">     <div class="embed-responsive" *ngif="contenturl">       <object [attr.data]="contenturl"               type="application/pdf"               class="embed-responsive-item">         <embed [attr.src]="contenturl"                type="application/pdf" />       </object>     </div>     <p><a [href]="contenturl">pdf download</a></p>   </div>   <div class="app-modal-footer">     <button type="button" class="btn btn-default" (click)="modal.hide()">close</button>   </div> </app-modal> 

in component set contenturl this:

public contenturl: safeurl; public setcontent() {     this.contenturl = this._sanitizer.bypasssecuritytrustresourceurl("/img/test.pdf"); } 

the popup opens nicely, not show embedded pdf. not try load url service. download link works nicely , asks if pdf should saved disc or opened.
tried embed pdf outside of popup no avail, too.
tried chrome, edge , ie. none displays embedded pdf.

so how show/embed pdf in angular component?

try use module opening pdf inside app, eg. https://www.npmjs.com/package/ng2-pdf-viewer.

check answer: angular 2 how display .pdf file.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -