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

本文标签: javascriptLoading external scripts within angular html viewsStack Overflow