1

I have to use few third-party scripts in my angular app, till now I have been loading these in my index.html and for the code which make use of these scripts, I have created a service.

Now I want to move these third-party scripts inside service itself, so that,

  1. I have more control over them as I want to load different versions of these scripts based on the environment they are being executed.
  2. Also to make my index.html less cluttered.

I can move and load these scripts in the service by loading them by creating script tag on head, my problem is, till the time these scripts are loaded I don't want my service which uses these to execute, as it will result in error.

Is there a way, either in angularjs or just JS, to know when these scripts are loaded and then only execute my code in service?

Or is there a better way of handling this?

Harsha
  • 717
  • 1
  • 11
  • 23
  • Would you like to load the external js on required? You can try angularjs with requirejs feature. – Janty Jul 30 '15 at 15:17
  • Please refer http://stackoverflow.com/questions/15939913/single-page-application-load-js-file-dynamically-based-on-partial-view . You will get pretty explained answer from jpmorin. – Janty Jul 30 '15 at 15:18
  • Thanks Janty, I just want to avoid using require or something similar as that I feel will be overkill. Would like to know if there is someway of doing this in angular itself. If not then I think I will use oclazyload which seems simple. – Harsha Jul 31 '15 at 04:55

0 Answers0