StevieB
StevieB

Reputation: 6533

Angular loading specific 3rd party scripts in partial views ui-router

In my app I have ui-router set up, and in one particular state i.e. "MAP" I want to load a 3rd party Javascript file.

Right now I have it as part of my Index.html at the bottom of the page. But i thought it would be better practice to only load this in view which needs it.

What is the best way to include this script in only specific partial views ?

Upvotes: 2

Views: 406

Answers (1)

CodyBugstein
CodyBugstein

Reputation: 23312

Turns out you can simply include the <script> tag in your partial. Works perfectly fine for me.

Also, if you have a window.onload function, you can replace it with a self invoking function like

(function(param){
     alert("partial running");
     bla bla....
})();

so it will run when the partial is pulled up.

Upvotes: 1

Related Questions