1

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.com/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

3
  • do you want to load script from partial..then Simply it won't possible 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? Commented May 7, 2015 at 13:28
  • do look at this, using directive..I'm not sure gist.github.com/endorama/7369006 Commented May 7, 2015 at 13:32

1 Answer 1

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.com/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>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply - this unfortunately does nothing :(
@CarlTaylor1989 you're right, I didn't test the code, sorry. Now I'm sure it works, sorry again.
Thank you that works. However I have a separate issue now with angular not liking the cross origin domain script! I believe there is no way around that hmmm...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.