如何绑定<script>AngularJS 中元素的 src 属性 [英] How to bind <script> element's src attribute in AngularJS

查看:26
本文介绍了如何绑定<script>AngularJS 中元素的 src 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 HTML <script> 元素的 src 属性绑定到我的 angular 控制器中的变量,以便我可以从控制器更新它而无需处理任何 UI.

I am trying to bind the src attribute of an HTML <script> element to a variable in my angular controller, so that I can update it from controller without dealing with any UI.

到目前为止,我已经尝试了所有这些选项:

So far I've tried all these options:

<script type="text/javascript" ng-src="{{sourceUrl}}"></script>
<script type="text/javascript" src="{{sourceUrl}}"></script>
<script type="text/javascript" ng-src="sourceUrl"></script>

在我的控制器中,我有:

In my controller I have:

$scope.sourceUrl = "https://<some url goes here>";

在设置 $scope.sourceUrl 后在浏览器中运行页面时,没有对 sourceUrl 的传出请求,所以我确定我做错了什么.有什么想法吗?

When running the page in the browser after the $scope.sourceUrl gets set there is no outgoing request to sourceUrl, so I am sure I am doing something wrong. Any ideas?

我发现了几篇关于 <img> 元素的 src 属性的帖子,ng-src 应该像他们说的那样工作,但我猜测

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