Trying something like this to get to work…
Hi, I am trying Ionic and loving the way it works. I am building my first ionic mobile app and trying to keep things neat and tidy. In my AngularJS projects, I use to have a controllers folder where all my controllers live (one controller per file), then in each file I would do something like this:
angular.module(‘starter’, )
.controller('PetIndexController', function($scope, PetService)
{
$scope.pets = PetService.all();
})
and the dependencies in the module declaration within app.js would look something like,
angular.module(‘starter’, [‘ionic’,])
.config ( etc…
As you can see, in this example I am attaching a controller to the main app module and it works when writing an angular app, for some reason this is not the case in my Ionic project, as it seems to need a new module for each file defining a controller (think the same happens for services, factories and so on). I know the sample project uses a single file for all controllers and a single services.js file for all factories, each one becoming a separate module, but I would really like to have my controllers and services as part of the main module and defined in different files each one, and correctly classified within controllers and services folders, thus, leaving the module without dependencies other than ionic itself. In this way I can add modules that provide new functionality to the app when needed in a more semantic way.
The way it is now looks a little convoluted to me, since if, for example, I have, let’s say 20 controllers with an average of 50 lines each one, the controllers file would grow in a way that it would become some more difficult to maintain. On the other hand, removing the extra modules from the dependencies in the main module (app.js), would look cleaner, after all, if the controllers are for the main module, they probably should be part of the module itself, same for services and factories…
Probably I am getting something wrong, or because I am coming from the desktop RIAs world, I am seeing this from a wrong standpoint. I have tried to move the controllers into different files for hours now and every single try has resulted in getting a blank page (error). Is there any dependency in the Ionic framework to a component that enforces certain file structure in the project AngularJS files?
I appreciate your comments on this matter, also if you know of any good piece of documentation where I can read more on the subject, that would be awesome.