Where to reference controllerjs scripts in angular app

I just started learning angular.js with .NET MVC, but the main problem I think is that in all the tutorials people end up linking 10 controllers and 10 services on the main (_Layout) page, which mostly looks bad ...

Now I know this must sound silly, but I tried to refer to a specific controller / service on its specific page, but then angular won't work (for some silly reason). To say the scripts are loaded, they just don't work!

Can I end up mining all the controllers / services in 1 big file and link to it in the layout page, or is this another way to do it?

+3


source to share


1 answer


Typical Approaches:



  • Your main page (for example index.html

    ) loads all your Angular JavaScript files with separate tags <script>

    . Thus, all definitions are available for the entire application. In most single page web applications, you will only have one main page; the rest of your content comes in as needed (e.g. dumped into an element ng-view

    via a router).
  • You are using some kind of external build process (like a Gulp task) to bundle all your individual JavaScript files into one JavaScript file (minified or not); you then pull in that file.
+2


source







All Articles