admin管理员组文章数量:1417422
I have signed up to a paid version of Polldaddy and was provided this script tag (minus the proper id).
<script type="text/javascript" charset="utf-8" src=".js"></script>
This script has to be loaded within a div in a view of mine - and it is not working. Does angular have an issue with loading scripts within a view? Is it possible? If so, could you help me understand how to do it please?
Let me know if you need more info.
Thanks
I have signed up to a paid version of Polldaddy and was provided this script tag (minus the proper id).
<script type="text/javascript" charset="utf-8" src="http://static.polldaddy./p/0000000.js"></script>
This script has to be loaded within a div in a view of mine - and it is not working. Does angular have an issue with loading scripts within a view? Is it possible? If so, could you help me understand how to do it please?
Let me know if you need more info.
Thanks
Share Improve this question asked May 7, 2015 at 13:19 AcolosAcolos 752 silver badges12 bronze badges 3- do you want to load script from partial..then Simply it won't possible – Pankaj Parkar Commented May 7, 2015 at 13:24
- Yes, I wanted to load a script element within a view html. Why is this not possible and is there a workaround? – Acolos Commented May 7, 2015 at 13:28
- do look at this, using directive..I'm not sure gist.github./endorama/7369006 – Pankaj Parkar Commented May 7, 2015 at 13:32
1 Answer
Reset to default 4You can't load a script inside an Angular app due the Angular script directive, so you need to create your own directive. Something like this:
function polldaddy() {
var injectScript = function(element) {
var scriptTag = angular.element(document.createElement('script'));
scriptTag.attr('charset', 'utf-8');
scriptTag.attr('src', 'http://static.polldaddy./p/0000000.js');
element.append(scriptTag);
};
return {
link: function(scope, element) {
injectScript(element);
}
};
}
angular
.module('myApp')
.directive('polldaddy', polldaddy);
and then in your HTML:
<div polldaddy></div>
本文标签: javascriptLoading external scripts within angular html viewsStack Overflow
版权声明:本文标题:javascript - Loading external scripts within angular html views - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745265441a2650569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论