Insert controller into the application from the requested template

0

I'm creating an angular application where, on the home page, I use a controller to do some validation before proceeding with the application login. My question is, do I have to "instantiate" the controllers of each template only when I request that template? I ask this because I do not want to have 1 controllers file with all the controllers because it is illogical in the MVC development pattern and not counting that delays at startup of the application. Putting in a draft ("kicking") I think it would be something like:

Template: registration page

<script src="js/controllers/CadastroCtrl.js"></script>
<ion-view view-title="Cadastro" ng-controller="CadastroCtrl">
    <ion-content>
        <h1>Cadastre alguma coisa</h1>
    </ion-content>
</ion-view>

Template: list page

<script src="js/controllers/ListagemCtrl.js"></script>
<ion-view view-title="Listagem" ng-controller="ListagemCtrl">
    <ion-content>
        <h1>Liste alguma coisa que foi cadastrada no outro template</h1>
    </ion-content>
</ion-view>

Would that be it? Does anyone have a better solution for handling the dependencies of each template? I gave the controller example but if I also have as a dependency some service (factory) or something like that would also fall into this question ...

    
asked by anonymous 15.05.2015 / 17:35

1 answer

1

What you need is to use a framework that manages your dependencies. This allows you to separate each controller, service, directive, into separate files, and manage them so that they are loaded only when needed. Home Take a look at RequireJS Home For an example of how the code works, see a friend's github .

    
23.06.2015 / 15:34