使用&LT加载外部脚本,脚本SRC =" ...">在角 [英] Loading an external script using <script src="..."> in Angular

查看:116
本文介绍了使用&LT加载外部脚本,脚本SRC =" ...">在角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要包括在URL中的会话ID(通常我不会做一个剧本,但我使用Crocodoc嵌入到文档的页面,他们似乎并没有把这样做的另一种方式它不使用iframe这是不定制):

I need to include a script that has a session ID in the URL (I wouldn't normally do this, but I'm using Crocodoc to embed documents into the page and they don't seem to have another way of doing it without using an iFrame which isn't customizable):

<!--sets a global variable "_doc" that is needed for initialization-->
  <script src="//crocodoc.com/webservice/document.js?session=tohY5vh3dPjUbmW6_imSQFshvQUsJ3fuJFyG7CxBU-E3AArTbELI3U0bSJBm6z5ZKtXpJQCnJ-EU1J2WGbuu6WH4e3Bglcy38TplHg"></script>

我想简单的事情,如:

I tried simple things like:

<script ng-src="//crocodoc.com/webservice/document.js?session={{ file.crocodoc_session }}"></script>

这写标签了罚款,但该脚本从未要求。我只用SRC也尝试过,而不是NG-SRC,但让与请求{{file.crocodoc_session}}中的URL,并且不会使另一个请求一旦会话ID值实际写入。

This writes the tag out fine, but the script is never requested. I also tried using just "src" instead of "ng-src" but that makes a request with "{{ file.crocodoc_session }}" in the URL, and doesn't make another request once the session ID value is actually written.

我试过的最后一件事是做一个编译功能,我使用jQuery来设置src属性指令。这工作,希望我无法弄清楚如何会话ID传递给编译功能。我使用的元素在会话属性,但是当我通过一个变量(或使用session ={{file.crocodoc_session}})我得到的变量名作为一个字符串,而不是它的价值。

The last thing I tried was to make a directive with a compile function, in which I use jQuery to set the src attribute. That worked, expect that I couldn't figure out how to pass the session ID to the compile function. I used a "session" attribute on the element, but when I pass a variable (or use session="{{ file.crocodoc_session }}") I get the variable name as a string instead of it's value.

推荐答案

请评价控制器内的链接,将其分配给一个范围的变量,然后在NG-SRC引用它。

Try evaluating the link inside the controller, assigning it to a scope variable and then referencing it in the ng-src.

这篇关于使用&LT加载外部脚本,脚本SRC =&QUOT; ...&QUOT;&GT;在角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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