2017-09-22 15 views
5

Tôi đang cố mở tệp .pdf trong bộ nhớ cục bộ bằng iFrame. Mã tôi đã thử là như sau.Cách mở pdf trong bộ nhớ cục bộ trong Angular2 HTML5?

Trong file HTML

<object [data]="sanitizer.bypassSecurityTrustResourceUrl(selectedItem.FilePath)" type="application/pdf"> 
<iframe [src]="sanitizer.bypassSecurityTrustResourceUrl(selectedItem.FilePath)"> 
</iframe> 
</object> 

trong Component.ts nộp

import { DomSanitizer } from '@angular/platform-browser'; 

this.selectedItem.FilePath="D:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStore\beta\1\145\pdf.pdf" 

mà không khử trùng nó sẽ ném một ngoại lệ như sau.

ERROR Error: unsafe value used in a resource URL context (see 
http://g.co/ng/security#xss) 
    at DomSanitizerImpl.webpackJsonp.../../../platform- 
browser/@angular/platform-browser.es5.js.DomSanitizerImpl.sanitize 
(platform-browser.es5.js:3970) 
    at setElementAttribute (core.es5.js:9320) 
    at checkAndUpdateElementValue (core.es5.js:9291) 
    at checkAndUpdateElementInline (core.es5.js:9238) 
    at checkAndUpdateNodeInline (core.es5.js:12325) 
    at checkAndUpdateNode (core.es5.js:12271) 
    at debugCheckAndUpdateNode (core.es5.js:13132) 
    at debugCheckRenderNodeFn (core.es5.js:13111) 
    at Object.eval [as updateRenderer] (McDocumentsComponent.html:110) 
    at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13096) 

Với chất vệ sinh, nó sẽ không mở tệp. Tôi đang làm gì sai? Làm cách nào để mở tệp .pdf trong máy chủ cục bộ. ?

Trả lời

0

Con đường dường như không đúng:

this.selectedItem.FilePath="D:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStoreD:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStore\beta\1\145\pdf.pdf" 

Bạn lặp lại hai lần phần

D:\WorkDir\Exceline\US.Exceline.GMS\US.Common.Web.Web\DocumentStore 
+0

nó phải ở trong một nhận xét. –

+0

Xin lỗi vì lỗi của nó. Vẫn không hoạt động –

Các vấn đề liên quan