AngularJs使用$ scope变量作为URL嵌入MS Word文档 [英] AngularJs embedding an MS Word doc using a $scope variable as the URL

查看:110
本文介绍了AngularJs使用$ scope变量作为URL嵌入MS Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我对URL进行硬编码,则可以在互联网上找到一个随机的MS Word单词文档,该文档可以工作:

Embedding a random MS Word word doc, which I found on the internet, works if I hard code the URL:

<iframe src="http://docs.google.com/gview?url=https://d9db56472fd41226d193-1e5e0d4b7948acaf6080b0dce0b35ed5.ssl.cf1.rackcdn.com/spectools/docs/wd-spectools-word-sample-04.doc&embedded=true"></iframe>

但是,我想通过AJAX获取URL,所以我将HTML更改为

However, I want to get the URL by AJAX, so I changed the HTML to

<iframe src="{{cvUrl}}&embedded=true"></iframe> 

,但甚至在我的JS中对$scope变量进行硬编码:

but even hardcoding that $scope variable in my JS:

$scope.cvUrl = 
    'http://docs.google.com/gview?url=https://d9db56472fd41226d193-1e5e0d4b7948acaf6080b0dce0b35ed5.ssl.cf1.rackcdn.com/spectools/docs/wd-spectools-word-sample-04.doc';

给予

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.24

这似乎很基本-我做错了什么?

This seems quite basic - what am I doing wrongly?

推荐答案

您应使用 $ sce .trustAsResourceUrl

var cvUrl = 
'http://docs.google.com/gview?url=https://d9db56472fd41226d193-1e5e0d4b7948acaf6080b0dce0b35ed5.ssl.cf1.rackcdn.com/spectools/docs/wd-spectools-word-sample-04.doc&embedded=true';

$scope.cvUrlTrusted = $sce.trustAsResourceUrl(cvUrl);

和HTML:

<iframe ng-src="{{cvUrlTrusted}}"></iframe>

演示小提琴

<iframe src="{{cvUrl}}&embedded=true"></iframe> <!-- wrong syntax -->

或:

<iframe ng-src="{{cvUrlTrusted + '&embedded=true'}}"></iframe>

由于政策原因也不起作用,因此您需要通过$sce完整URL

doesn't work too because of policy, so you need pass through $sce full URL

这篇关于AngularJs使用$ scope变量作为URL嵌入MS Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆