0

When I paste any <script> into my angular view, it fails silently and does not load the script.

I'm trying to embed a Saucelabs video into my AngularJS project. (Documentation, example script)

<script src="https://saucelabs.com/video-embed/<jobId>.js?auth=<authToken>"></script>

However, pasting <script>alert('test')</script> into my view doesn't appear to work either, so I'm thinking this is default behaviour of Angular.

Clearly, logic doesn't really belong in the view, so generally I don't need to include any <script>s here, but in this case, I don't really see an alternative.

Any ideas?

2
  • ah, good find, I did search for duplicates, but did not find that... let me verify that this indeed is the same situation... Commented Feb 28, 2014 at 16:55
  • ... and it is the same situation, but this question's answers seem to be better. Commented Feb 28, 2014 at 18:15

1 Answer 1

1

Here is a hack I am using for loading scripts in the controller.

Btw, I put in into resolve of the view/state to wait till script loads.

$http.get('http://api-maps.yandex.ru/2.0/?load=package.full&lang=ru-RU').then(function(data){
    window.eval(data);
    deffered.resolve() // because I'm using it in the resolve part
});

Specify your own URL and thats works.

Another option could be using RequireJS, but I've not used it.

Sign up to request clarification or add additional context in comments.

2 Comments

Hmmm, I'll give this a try (on Monday), but I kinda think it won't work. The script in question looks like it actually requires the <script> tag to be present, as thats how it knows where to inject the html (but I may be confused)
<script> tag is actually loading remote script and evaluates (runs) it. My code does the same. It will inject the code on the global scope, because I use eval on the window object.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.