Skip to content

Instantly share code, notes, and snippets.

@matyax
Last active April 26, 2016 16:30
Show Gist options
  • Save matyax/9623cb90c57a6eb4f2e6f99c4747fd6d to your computer and use it in GitHub Desktop.
Save matyax/9623cb90c57a6eb4f2e6f99c4747fd6d to your computer and use it in GitHub Desktop.
Angular 1.x boilerplate
/**
* Module definition
* Usage:
* <body ng-app="moduleName">...
*/
angular.module('moduleName', [ ])
.config(function(...) {
//custom config for this module if necessary
});
/**
* Controller definition
* Usage:
* <div ng-controller="ControllerName">...
*/
angular.module('moduleName')
.controller('ControllerName', ['$scope', 'somethingService', 'somethingProvider',
function ControllerName($scope, somethingService, somethingProvider) {
}]);
/**
* Provider definition
* Usage:
* Dependency injection
*/
angular.module('moduleName')
.provider('somethingProvider', function SomethingProvider () {
var config = {
};
this.$get = function() {
return {
getSomething: function () {
return config.something;
},
getOtherThing: function {
return 'Static value';
}
};
};
});
/**
* Service definition
* Usage:
* Dependency injection
*/
angular.module('tid.coreModule')
.factory('somethingService', [ function SomethingServiceFactory() {
return {
api: api
};
function api(...) {
//...
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment