angular - angular2 rc.6 如何禁用显示 pdf 的嵌入 html 标签上的清理

标签 angular

我真的不明白我在这里做错了什么:

模板:

<embed [src]="pdfUrl" width="500" height="100%" type='application/pdf'>

类:

pdfURL;
constructor(private domSanitizer : DomSanitizer) {}
ngOnInit() {
    this.pdfUrl = this.domSanitizer.bypassSecurityTrustUrl('http://example.com/pdf.pdf')
}

这实际上并没有加载 <embed>但不会引发错误。

我尝试使用 SafeUrl输入 pdfURLbypassSecurityTrustResourceUrl() . <embed>标记收到正确的 url,但未显示任何内容。

最佳答案

我猜应该是:

this.pdfUrl = this.domSanitizer.bypassSecurityTrustResourceUrl('url')

并像这样使用它:

<iframe [src]="pdfUrl" width="500" height="600" type='application/pdf'></iframe>

参见 Plunkr

更新(Chrome中的embed标签有bug)

对于 embed 标签,您可以通过 outerHTML 重新注入(inject) embed 标签:

this.renderer.setElementProperty(el, 'outerHTML', el.outerHTML)

参见 plunker 对于这种情况

关于angular - angular2 rc.6 如何禁用显示 pdf 的嵌入 html 标签上的清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39393431/

相关文章:

javascript - *ngFor 循环无法在 Angular 9 中显示 json 数据

javascript - 弹出项目后的 Angular-cli.json

angular - ionic 3 中的 HTTP 问题

angular - 从嵌套表单组获取控件

angular - 如何以 Angular 获取嵌套表单组的控件

angular - karma 无法识别 Angular Directive(指令)

jquery - Angular 2 为 jQuery 的每个组件实例提供唯一的 id

Angular:如何通过 Injector 在 ngComponentOutlet 中传递数据

angular - 成功登录后,get 和 post api 不起作用

angular - 嵌套 FormGroup 的 FormControl 是 ng-valid 尽管 FromGroup 是 ng-invalid