Once an entire configuration block has finished, the run phase of an AngularJS module can execute. During this phase, you can implement any code necessary to instantiate the module. You cannot implement any provider code during the run block because the entire module should already be configured and registered with the dependency injector by this point.
The run
block is implemented by calling the run()
method of the Module
object, using the following syntax:
run(function([injectable, . . .]))
A function with the instance injectable
parameters is passed in. The injectable
parameters should only be instances of injectors because configuration should already have been completed.
The following is a basic implementation of the run
block continued from the example above:
myModule.run(function(startTime) {
startTime.setTime((new Date()).getTime());
});
Notice that the startTime
instance defined in the config()
section above is passed into the run()
function. This allows the run()
function to update the startTime
provider to a new value.
3.145.204.201