After making almost 100 controllers for one system, we’ve established a standardized method for controllers.
First: we no longer do any Javascript directly. Typescript is completely taken over. Our development speed has increased substantially. It took a while, but now none of us would go back.
We’ve organized our structure into modules:
Application.Domain.[whatever common modules we will use across all controllers]
Application.Controllers.[whatever controller or set of controllers we will be loading]
Application.Types.[All standardized interfaces we’ve made ourselves]
///module Application.Controllers.StandardizedNotes { class notes { static $inject = [ '$scope', '$http', '$location', '$window', '$filter', '$log', '$cookies', '$routeParams' // standard angular modules , 'jobFact' // custom modules and factories ]; public Offices: any; public office_id: number; constructor( private $scope: ng.IScope, private $http: ng.IHttpService, private $location: ng.ILocationService, private $window: ng.IWindowService, private $filter: ng.IFilterService, private $log: ng.ILogService, private $cookies: Types.ICookiesService, private $routeParams: ng.RouteDefinition, private jobFact: any ) { var self = this; self.$window.document.title = "Standardized Notes"; } } app.controller("notes", notes); }
While this isn’t super exciting, we can cut and past this clip into any new controller we want to make, remove any libraries we don’t need, add any custom modules we will need, and just move on.
The “ref” link at the top is to an application file. THAT file then contains references to all of our typing and other needs for Intelliesense.
There are a LOT of ways to do this, but we’ve honestly not found a faster and safer way of getting an angular controller up and running.