-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put angular modules in their own files #86
Comments
This applies to the models in services.js too. |
One thing to note is that Angular groups modules by a namespace (see below): https://github.com/codeforamerica/trails-mobile/blob/master/www/js/application/services.js#L1319 If we put every module in a separate file, we'll either have to make separate angular modules for every controller,directive and service or put make each module group globally available to the window. That's not terrible, I just wanted to document this for the sake of discussion. One thing we'll need to be sensitive of is avoiding namespace collisions on the module variables. |
An option is to use RequireJS to handle module dependencies (as discussed here: http://marcoslin.github.io/angularAMD/#/home), though I'm unclear whether AMD modules are necessarily needed if modules aren't being loaded asynchronously, since Angular has its own module system. Seems it could be as simple as: http://stackoverflow.com/questions/20087627/how-to-create-separate-angularjs-controller-files |
FWIW, that's pretty much how we do it in another Angular project I'm working on. I'm not sure the additional boilerplate for AMD is really worthwhile, as it gets pretty repetitive w/r/t the angular injector syntax. (Also worth noting is that Angular runs module constructors when they are first injected, so the order you concatenate files in mostly doesn't matter—though you do have to make sure module X is declared before you, say, add a controller to it. That controller can still inject something that comes later in the file, though.) The only other suggestion I'd make is to group files by feature area (e.g. trail data, map stuff, main display+detail display, search) rather than by service/directive/controller. That's a bit larger of a refactor, though. |
Break apart the
controllers.js
into a controllers directory withcontrollers/nofications.js
andcontrollers/app.js
. Each js file should have one module.The text was updated successfully, but these errors were encountered: