我已经注册了 Polldaddy 的付费版本,并获得了这个脚本标签(减去正确的 ID)。
<script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/0000000.js"></script>
在我的 View 中,此脚本必须加载到一个 div 中 - 但它不起作用。 Angular 在 View 中加载脚本有问题吗?是否可以?如果是这样,你能帮我理解怎么做吗?
如果您需要更多信息,请告诉我。
谢谢
最佳答案
由于 Angular script,您无法在 Angular 应用程序中加载脚本指令,因此您需要创建自己的指令。 像这样:
function polldaddy() {
var injectScript = function(element) {
var scriptTag = angular.element(document.createElement('script'));
scriptTag.attr('charset', 'utf-8');
scriptTag.attr('src', 'http://static.polldaddy.com/p/0000000.js');
element.append(scriptTag);
};
return {
link: function(scope, element) {
injectScript(element);
}
};
}
angular
.module('myApp')
.directive('polldaddy', polldaddy);
然后在您的 HTML 中:
<div polldaddy></div>
关于javascript - 在 Angular html View 中加载外部脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30102299/