Created
August 27, 2014 13:26
-
-
Save richardvanbergen/45c833b7bdf40cf274c0 to your computer and use it in GitHub Desktop.
Method to improve Angular.js's handling of module definitions without modifying angular itself.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, angular) { | |
'use strict'; | |
/** | |
* Register or fetch a module. Angular doesn't handle modules in this way usually, overriding the module instead of | |
* extending it. So controllers/services/directives/etc can't share the same namespace without separating the | |
* module definition from the module implementation, leading to files with one line in them or one file of module | |
* definitions. | |
* | |
* @param name {string} Module name. | |
* @param dependencies {Array} List of modules this module depends upon. | |
* @param configFn {function} Config function to run when module loads (only applied for the first call to | |
* create this module). | |
* | |
* @returns {*} The created/existing module. | |
*/ | |
window.module = function(name, dependencies, configFn) { | |
var module; | |
try { | |
module = angular.module(name); | |
} catch(e) { | |
module = angular.module(name, dependencies, configFn); | |
} | |
return module; | |
}; | |
})(window, angular); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment