1

I need to include javascript files dynamically using angular.js. Suppose i have the below project html view structure.

1-index.html.

     a)hod.html-hodcontroller.js
         i)home.html.-homecontroller.js
         ii)about.html.-aboutcontroller.js

     b)Princpal.html-princpalcontroller.js

         i)home.html-homecontroller.js
          ii)about.html -aboutcontroller.js

Let me to explain the above structure.I have one master page(i.e-index.html). hod.html and Princpal.html are the partial view to index.html page. Each home.html and about.html are the again partial view to hod.htmland Princpal.html so finally these are nested view.Here i am including all js files at a time in index.html page But here i need when any partial view will attach in index page only the that related .js files will attach in the index page not the all page.So please help me to do this using angular.js.

  • Please review `ui-router` in relation to nested views in angular and how this should be achieved in a SPA. Review the concepts of `ng-include` and directives especially in relation to loading partial views and I think this will help you. – markyph Oct 17 '15 at 08:50
  • @markyph : i am also using ui-router for this.Can you edit one example based on this requirement. –  Oct 17 '15 at 08:57

1 Answers1

0

What you are trying to do is not the best way to create an angular app. Usually you want all the code to be in one js file.

Of course when you develop they will be different files, so you should use a task runner like Grunt or Gulp to do that for you.

I suggest that you use a Yeomen generator with an angular generator

It will setup a working angular app for you with Grunt and other interesting stuff.

Emanuele Spatola
  • 555
  • 3
  • 10
  • @ Emanuele : No, i dont want to all code into one js file.Here i need how to manage include js file according to the view.Read my post again. –  Oct 17 '15 at 09:05
  • then you need to create multiple angular apps, as with angular you cannot dynamically add controllers. But if you really want to follow this path, have a look at this: http://stackoverflow.com/questions/15250644/loading-an-angularjs-controller-dynamically – Emanuele Spatola Oct 17 '15 at 09:16