The Module
object provides special constructor methods to add providers for the AngularJS objects that you need to implement in your modules. These specialized methods enable you to add definitions for the following types of objects:
■ animation(
name,
animationFactory)
■ controller(
name,
controllerFactory)
■ filter(
name,
filterFactory)
■ directive(
name,
directiveFactory)
The reason these are specialized methods is that there are corresponding animation
, controller
, filter
, and directive
objects defined in AngularJS for these provider methods.
Each of these objects is covered in more detail in later chapters. For now, here’s a quick look at a basic controller definition:
var mod = angular.module('myMod', []);
mod.controller('myController', function($scope) {
$scope.someValue = 'Some Value';
});
A simple module named mod
is created, and then the controller()
method is called and passed in myController
along with a controllerFactory
function. The controllerFactory
function accepts the $scope
variable as a parameter. This is because AngularJS has a built-in controller object and knows that all controller objects must receive a scope object as the first parameter.