javascript - Loading external scripts within angular html views - Stack Overflow

I have signed up to a paid version of Polldaddy and was provided this script tag (minus the proper id).

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
Add a ment  | 

1 Answer 1

Reset to default 4

You 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745265441a4619424.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信