Chapter 2
Syntax for declaring the configure and run blocks
As described in Chapter 1, Angular Zen the process of bootstrapping an AngularJS
application is divided in two distinct phases, the configure phase and the run
phase. Each module can have multiple configure and run blocks. We are not
restricted to a single one.
It turns out that AngularJS supports two different ways of registering functions
that should be executed in the configuration phase. We saw already that it is
possible to specify a configuration function as the third argument to the
angular.module function:
angular.module('admin-projects', [], function() {
//configuration logic goes here
});
The preceding method allows us to register one and only one configure block.
On top of this module declaration becomes quite verbose (especially, if a module
specifies dependencies on other modules). An alternative exists is the form of the
angular.config method:
angular.module('admin-projects', [])
.config(function() {
//configuration block 1
})
.config(function() {
//configuration block 2
});
As you can see, the alternative method makes it possible to register several
configuration blocks. This might come handy to split big configuration functions
(especially ones with multiple dependencies) into smaller, focused functions.
Small, cohesive functions are easier to read, maintain and test.
In the SCRUM sample application we are going to use the later form of registering
configuration and run functions as we find it more readable.
Downloading the example code
You can download the example code files for all Packt books you have
purchased from your account at http://www.packtpub.com. If you
purchased this book elsewhere, you can visit http://www.packtpub.
com/supportand register to have the files e-mailed directly to you.