Question

Just started with angularjs. It's really great. I would like to have my app to be as modular as possible. My question: Should I have one script tag per angularjs controller (service etc)? Is there a way to load my angular controllers (services etc) from the server, as needed? Angular does it somehow? Am I missing something?

UPDATE

Perhaps I haven't made myself clear. I wish to have one javascript file per angularjs controller (service etc). Just like I have one file per nodejs module server-side.

Was it helpful?

Solution

I suggest you to take as starting point the angular seed project. You could find it on Github.

This project is an application skeleton for a typical AngularJS web app. You can use it to quickly bootstrap your angular webapp projects and dev environment for these projects.

This is the style they suggest to adopt for the controllers.js file:

'use strict';

/* Controllers */

function MyCtrl1() {}
MyCtrl1.$inject = [];


function MyCtrl2() {
}
MyCtrl2.$inject = [];

I also suggest this approach for the development environment. You could compress, and join the files when you will deploy to production.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top