Last active
August 29, 2015 14:09
-
-
Save dwelch2344/c858272bfe5fbc7a97e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(angular) { | |
var origMethod = angular.module; | |
angular.modules = {}; | |
/** | |
* Register/fetch a module. | |
* | |
* @param name {string} module name. | |
* @param reqs {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. | |
*/ | |
angular.module = function(name, reqs, configFn) { | |
reqs = reqs || []; | |
var module = null; | |
if (angular.modules[name]) { | |
module = origMethod(name); | |
module.requires.push.apply(module.requires, reqs); | |
} else { | |
module = origMethod(name, reqs, configFn); | |
angular.modules[name] = module; | |
} | |
return module; | |
}; | |
})(angular); |
This file contains hidden or 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
'use strict'; | |
var prefix = 'demo'; | |
var deps = []; | |
// dynamically load any modules that have the same prefix as this module | |
angular.forEach(angular.modules, function(e){ | |
if(e.name.length > prefix.length && e.name.substring(0, prefix.length + 1) == prefix + '.'){ | |
deps.push(e.name); | |
} | |
}); | |
var app = angular.module(prefix + '.app', deps); | |
app.config(function (CONFIG, $urlRouterProvider, $stateProvider, $httpProvider ) { | |
$urlRouterProvider.otherwise('/404'); | |
$stateProvider | |
.state('/', { | |
url: '/', | |
templateUrl: CONFIG.templatesPrefix + 'main.tpl.html' | |
}) | |
; | |
}) | |
.run(function($rootScopehi) { | |
console.log('Hello app'); | |
}); |
This file contains hidden or 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
angular.module('demo.register', ['demo.config']) | |
.config(function(CONFIG, $stateProvider){ | |
$stateProvider | |
.state('register',{ | |
url: '/register', | |
templateUrl: CONFIG.templatesPrefix + 'users/register.tpl.html', | |
controller: 'RegisterController' | |
}); | |
}) | |
.controller('RegisterController', function() { | |
console.log('RegisterController loaded'); | |
}) | |
; |
This file contains hidden or 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
<html> | |
<body ng-app> | |
<div ui-view></div> | |
<!-- build:js(src/main/webapp/WEB-INF) static/js/scripts.js --> | |
<!-- Libraries --> | |
<script src="client/bower_components/momentjs/moment.js"></script> | |
<script src="client/bower_components/modernizr/modernizr.js"></script> | |
<script src="client/bower_components/jquery/dist/jquery.js"></script> | |
<script src="client/bower_components/angular/angular.js"></script> | |
<script src="client/js/lib/angular-modules.js"></script> | |
<script src="client/bower_components/angular-ui-router/release/angular-ui-router.js"></script> | |
<script src="client/bower_components/angular-cookies/angular-cookies.js"></script> | |
<script src="client/bower_components/angular-sanitize/angular-sanitize.js"></script> | |
<script src="client/bower_components/angular-translate/angular-translate.js"></script> | |
<script src="client/bower_components/angular-translate-storage-cookie/angular-translate-storage-cookie.js"></script> | |
<script src="client/bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js"></script> | |
<script src="client/bower_components/angular-dynamic-locale/src/tmhDinamicLocale.js"></script> | |
<script src="client/bower_components/angular-base64/angular-base64.js"></script> | |
<!-- App code --> | |
<script src="client/js/config/config.js"></script> | |
<script src="client/js/users/register.js"></script> | |
<!-- Load our bootstrap last --> | |
<script src="client/js/main.js"></script> | |
<!----> | |
<!-- endbuild --> | |
</body> | |
</html> |
so angular.modules is an array? That is cool!!! I didn't know that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any angular modules prefixed with
demo.
that are included beforemain.js
will be automatically loaded.