The list of enabled modules should be provided for main module:
var enabledModules = [...];
angular.module('app', ['thirdParty', 'app.common'].concat(enabledModules));
Obviously, enabledModules
array can't be normally loaded with $http
, because the application isn't bootstrapped at this point. XHR or server-side templating may be be used to define it.
Alternatively, a separate application can be used to load prerequisites. Due to the use of DI, it can be thoroughly tested.
angular.module('app', ['thirdParty', 'app.common']);
angular.module('appInitializer', [])
.factory('loader', ($http) => {
return $http.get('enabled-modules').then((result) => result.data);
})
.factory('initializer', (loader, $document) => {
return loader.then((enabledModules) => {
$document.ready(() => {
angular.bootstrap($document.find('body'), ['app'].concat(enabledModules));
});
});
});
angular.injector(['ng', 'appInitializer'])
.get('initializer')
.catch((err) => console.error(err));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…