简体   繁体   English

Angular2 试图显示 PDF

[英]Angular2 trying to show a PDF

I am trying to show a PDF file on my page.我正在尝试在我的页面上显示 PDF 文件。 For do that I am using the object tag like this and it works:为此,我正在使用这样的对象标签,它可以工作:

<div style="width:100%;height:100%;position:relative;background-color:white">
  <object data="http://eloquentjavascript.net/Eloquent_JavaScript.pdf" 
    type="application/pdf" width="100%" height="100%">
    <param name="view" value="Fit" />
  </object>
</div>

But I need to set the object data dynamically, like this:但我需要动态设置对象数据,如下所示:

<div style="width:100%;height:100%;position:relative;background-color:white">
  <object data="{{url}}" 
    type="application/pdf" width="100%" height="100%">
    <param name="view" value="Fit" />
  </object>
</div>

I've defined the url but it didn't show the PDF file.我已经定义了 url,但它没有显示 PDF 文件。 I've created an example of waht I wanna do: http://plnkr.co/edit/6xE1Q7YzcD8eB0K4lP8Y我已经创建了一个我想做的例子: http : //plnkr.co/edit/6xE1Q7YzcD8eB0K4lP8Y

Please any suggestion what I am doing wrong?请提出任何建议我做错了什么?

Thanks and regards, Edu感谢和问候, Edu

Seems to work fine in Chrome.在 Chrome 中似乎工作正常。

Some browsers (IE) resolve {{url}}" before Angular got a chance to replace the binding by the bound value which results in an error because {{url}}` isn't a valid URL.一些浏览器 (IE) {{url}}" before Angular got a chance to replace the binding by the bound value which results in an error because解析{{url}}" before Angular got a chance to replace the binding by the bound value which results in an error because {{url}}` 不是有效的 URL。

You can prevent that by using您可以通过使用来防止这种情况

<object [data]="url" 

or或者

<object [attr.data]="url" 

or或者

<object attr.data="{{url}}" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM