I have module with directive and application which is module with controllers.
angular.module('ValidationWidgets', [])
.directive('validationfield', function () {
....
});
angular.module('MyPage', ['ValidationWidgets'])
.controller('MyFirstController', function ($scope) {
....
});
Is there some pretty syntax to declare many controllers in app module, because .controller('MyFirstController', function ($scope) { looks bad?
I want to write something like:
var myPage = angular.module('MyPage', ['ValidationWidgets']);
myPage.controllers.MyFirstController = function($scope) {
...
}
var app = angular.module("myApp", []);
app.controller("my controller", function(){});
or
var app = angular.module("myApp", []);
var controllers = {};
controller.myController = function(){};
app.controller(controllers);
Take a look at this video http://egghead.io/video/angularjs-thinking-different-about-organization/
The whole series is amazing to be honest.
To expand on what @Jacob Dalton said, you can do this:
Setup your routes:
app.config(['$routeProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/view1', {templateUrl: 'partials/view1', controller: 'View1Ctrl'}).
when('/view2', {templateUrl: 'partials/view1', controller: 'View2Ctrl'}).
otherwise({redirectTo: '/view1'});
}]);
Then you can declare your controllers by simply declaring a function:
function View1Ctrl($scope, $http) {
}
function View2Ctrl($scope, $http) {
}
Those functions will be auto wired as controllers. As stated before, however, this makes it less obvious that these functions are controllers.