【问题标题】:Parse error while rendering the pdf file in angularjs app在 angularjs 应用程序中呈现 pdf 文件时解析错误
【发布时间】:2015-07-05 13:22:06
【问题描述】:

当我尝试使用 angular-pdf-viewer 访问公开的 pdf 文件时,我在控制台上收到以下错误消息。

Error: [$parse:syntax] Syntax Error: Token ':' is an unexpected token at column 5 of the expression [http://pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf] starting at [://pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf].

这是我用于渲染 pdf 文件的 pdf 指令:

<pdf-viewer delegate-handle="my-pdf-container" url="http://pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf" scale="1" show-toolbar="true" ></pdf-viewer>

有人可以帮忙解决这个问题吗?

【问题讨论】:

  • 你能分享指令的代码吗?
  • @mirfan899 你解决了吗?

标签: angularjs pdf.js


【解决方案1】:

所有示例似乎都建议在范围上定义 url 并引用它。但是您可以尝试以下方法,其中 stringifys url

<pdf-viewer delegate-handle="my-pdf-container" url="'http://pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf'" scale="1" show-toolbar="true" ></pdf-viewer> 

【讨论】:

  • 错误消失了,但我有更多错误。 OPTIONS http://pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf 403 (Forbidden) XMLHttpRequest cannot load http://pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. The response had HTTP status code 403. pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf:1 OPTIONS http://pucdocket.s3.amazonaws.com/VA/PUE-2010-00039/122913.pdf 403 (Forbidden)
  • 这是我的应用配置:app.config(['$httpProvider', function ($httpProvider) { delete $httpProvider.defaults.headers.common["X-Requested-With"]; $httpProvider.defaults.useXDomain = true; $httpProvider.defaults.withCredentials = false; $httpProvider.defaults.headers.common["Accept"] = "application/json"; $httpProvider.defaults.headers.common["Content-Type"] = "application/json"; } ]);
  • @mirfan899 我认为您看到此错误的原因是 CORS,因为您正在尝试在主机外部检索文件,请尝试使用 github.com/Rob--W/cors-anywhere 或创建自己的代理
猜你喜欢
  • 2014-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-24
相关资源
最近更新 更多