I'd like to load a controller when I change from one view to another.
For example, I'm in the home page and user wants to go to the log in page. I have a LoginController in a file that is not include in app.js(main AngularJS script) that I want to load only if the user goes to Login page.
I saw differents solutions but are very complicated, my controllers are very simple and I only want to have them in different files but I don't want to load a controller if I are not going to use them.
Thanks.
You probably need ng-route. This is a module that does exactly what you want to. (along with other functionality -> ngRoute. you define routes in the next way.
Also, you have to declare the loginController, but don't worry, a controller gets destroyed if you change the view it was bound to, and recreated when you open your loginpage again.