angular.module('moduleName', [/* deps */]);
angular.module('moduleName');
angular.module('moduleName')
.animation()
.config()
.constant()
.controller()
.directive()
.factory()
.filter()
.provider()
.requires()
.run()
.service()
.value()
<body ng-app="my-module">
<div ng-view></div>
</body>
angular.module('myModule', ['ngRoute']);
angular.module('myModule').config(['$routeProvider', function($routeProvider) { $routeProvider .when('/detail/:id', { controller: 'DetailCtrl', template: 'detail.html' }); }]);
angular.module('myModule.controllers').controller('DetailCtrl', ['$scope', function($scope) { // gluecode }]);
<div> <span ng-repeat="greetings as greeting">{{greeting|lowercase}}</span> <button ng-click="doSomething()">{{buttonText}}</button> </div>
<span>{{value|filter-name:arg1:arg2:...}}</span>
$filter('filter-name')(value, arg1, arg2, ...)
angular.module('myModule.filters').filter('filterName', [ function() { return function(input, arg1, arg2, arg3) { return input + arg1 + arg2 + arg3; } }]);
<div ng-repeat="thing in things"> <span ng-dblclick="toggle(thing.id)">{{thing.description}}</span> <span ng-if="thing.additionalInfo">{{thing.additionalInfo}}</span> <a ng-href="thing.link.href">{{thing.link.text}}</a> <button ng-click="showDetailView(thing.id)"></button> </div>
angular.module('myModule.directives').directive('directiveName', [ function() { return { restrict: 'AEC', template: '<span>{{value}}</span>' } }]);
in template
<div> <directive-name></directive-name> </div>
compiled
<div> <span>some text</span> </div>
angular.module('myModule.directives').directive('directiveName', [ function() { return { scope: {} } }]);
<div> <directive-name an-argument="{{someValue}}"></directive-name> </div>
angular.module('myModule.directives').directive('directiveName', [ function() { return { scope: { anArgument: '=' // also: @ / & }, template: '<span>{{anArgument}}</span>' } }]);
<div> <span directive-name></span> </div>
angular.module('myModule.directives').directive('directiveName', [ function() { // this is javascript here so feel free to do whatever you want return function(scope, element, attrs) { element.text('hi'); } }]);
<div> <span>hi</span> </div>
<div> <directive-name><span>Some text</span></directive-name> </div>
angular.module('myModule.directives').directive('directiveName', [ function() { return { transclude: true, template: '<div ng-transclude></div>' } }]);
<div> <div><span>Some text</span></div> </div>
angular.module('myModule.directives').directive('directiveName', [ function() { return function(scope, element, attr) { element.on('mouseenter', function(event) { event.preventDefault(); // it's javascript, feel fre-- ahh you know... }); } }]);
angular.module('myModule.directives').directive('directiveOne', [ function() { return { scope: {}, controller: function($scope) { $scope.method = function() {}; } } }])
angular.module('myModule').directive('directiveNameTwo', [function() { return { require: '^directiveOne', link: function(scope, elements, attrs, directiveOneController) { directiveOneController.method(); } } }])
angular.module('myModule.controllers').controller('DetailCtrl', ['$scope', '$http', function($scope, $http) { $scope.data; $http.get('yourapi/yourresponse.json') .success(function(data, status, headers, config) { $scope.data = data; }) .error(function(data, status, headers, config) { // ... }); }]);
angular.module('myModule').value('foo', 'value value');
usage
angular.module('myModule.controllers').controller('CtrlName', ['$scope', 'foo', function($scope, foo) { $scope.name = foo; }]);
<div> <span>{{name}}</span> </div>
angular.module('myModule').constant('BAR', 'value value');
usage
angular.module('myModule.controllers').controller('CtrlName', ['$scope', 'BAR', function($scope, BAR) { $scope.name = BAR; }]);
<div> <span>{{name}}</span> </div>
angular.module('myModule.s').factory('myFactory', [function() { var self = {}; self.returnName = function() { return 'a name'; } return self; }]);
usage
angular.module('myModule').controller('CtrlName', ['$scope', 'myFactory',
function($scope, myFactory) { $scope.name = myFactory.returnName(); }]);
function ConstFct() { this.someValue = 0; this.someMethod = function() {}; } angular.module('myModule').service('myService', [ConstFct]);
usage
angular.module('myModule').controller('CtrlName', ['$scope', 'myService',
function($scope, myService) { $scope.name = myService.someMethod(); }]);