Created
July 13, 2016 17:45
-
-
Save BenArunski/1281d0dcb1fdbfab1f08cf7d16666c97 to your computer and use it in GitHub Desktop.
Angular Environment Bootstrap with ui-router
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> | |
... | |
<script> | |
(function() { | |
'use strict'; | |
var cb = function (cfg) { | |
angular.module('app.config', []).constant('CONFIG', cfg); | |
angular.element(document).ready(function() { | |
// instead of <html ng-app="main"> | |
angular.bootstrap(document, ['main']); | |
}); | |
}; | |
angular.injector(['ng']).get('$http').get('/other-app-on-tomcat/config.json').then( | |
function(res){ cb(res.data); }, | |
function(reason){ cb({failed: reason}) } | |
); | |
})(); | |
</script> | |
</body> | |
</html> |
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 () { | |
'use strict'; | |
angular | |
.module('main') | |
.config(config); | |
/** @ngInject */ | |
function config($stateProvider) { | |
$stateProvider | |
.state('app', { | |
abstract: true, | |
resolve: { | |
checkConfig: checkConfig | |
} | |
} | |
); | |
/* @ngInject */ | |
function checkConfig($q, CONFIG, $log) { | |
var d = $q.defer(); | |
var routeKiller = d.promise; | |
if(CONFIG.failed) { | |
cancelRouteAndMessage(CONFIG.failed); | |
} else { | |
success(); | |
} | |
function cancelRouteAndMessage(reason) { | |
$log.error('Is other-app-on-tomcat running? There was a problem fetching the config because of the error:'); | |
$log.error(reason); | |
d.reject('There was a problem fetching the config'); | |
} | |
function success() { | |
d.resolve('config is loaded and verified'); | |
} | |
return routeKiller; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment