Mastering Web Application

(Rick Simeone) #1

Packaging and Deploying AngularJS Web Applications


Even if function arguments were changed, the minification process can't touch
elements of the array, and AngularJS has enough information to find all the
dependencies for a given function.


If you want your code to be minification-safe, replace all functions
(declaring at least one dependency) with an array where initial
elements of an array correspond to the function's argument names
and the last element of an array contains the function itself.

The array-style Dependency Injection annotation syntax might look odd at times,
so let's skim over several examples taken from the SCRUM sample application.
Subsequent sections of this chapter show examples for the most common use cases.


All the code written for the sample SCRUM application contains
array-style DI annotations. You can refer to the code hosted on GitHub
to find examples of those annotations used in different situations.

Modules


The config and run functions on a module level can be injected with dependencies.
Here is an example of defining configuration time dependencies in the minification-
safe way:


angular.module('app')
.config(['$routeProvider', '$locationProvider', function
($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.otherwise({redirectTo:'/projectsinfo'});
}]);

Functions to be executed in run blocks can be annotated in the following fashion:


angular.module('app')
.run(['security', function(security) {
security.requestCurrentUser();
}]);
Free download pdf