Startup Logic
Configuration
[Style Y170]
Inject code into module configuration that must be configured before running the angular app. Ideal candidates include providers and constants.
Why?: This makes it easier to have a less places for configuration.
angular
.module('app')
.config(configure);
configure.$inject =
['routerHelperProvider', 'exceptionHandlerProvider', 'toastr'];
function configure (routerHelperProvider, exceptionHandlerProvider, toastr) {
exceptionHandlerProvider.configure(config.appErrorPrefix);
configureStateHelper();
toastr.options.timeOut = 4000;
toastr.options.positionClass = 'toast-bottom-right';
////////////////
function configureStateHelper() {
routerHelperProvider.configure({
docTitle: 'NG-Modular: '
});
}
}
Run Blocks
[Style Y171]
Any code that needs to run when an application starts should be declared in a factory, exposed via a function, and injected into the run block.
Why?: Code directly in a run block can be difficult to test. Placing in a factory makes it easier to abstract and mock.
angular
.module('app')
.run(runBlock);
runBlock.$inject = ['authenticator', 'translator'];
function runBlock(authenticator, translator) {
authenticator.initialize();
translator.initialize();
}