There is an excellent article of how to bootstrap an angular1 application asynchronously. This enables us to fetch a json from the server before bootstrapping.
The main code is here:
(function() {
var myApplication = angular.module("myApplication", []);
fetchData().then(bootstrapApplication);
function fetchData() {
var initInjector = angular.injector(["ng"]);
var $http = initInjector.get("$http");
return $http.get("/path/to/data.json").then(function(response) {
myApplication.constant("config", response.data);
}, function(errorResponse) {
// Handle error case
});
}
function bootstrapApplication() {
angular.element(document).ready(function() {
angular.bootstrap(document, ["myApplication"]);
});
}
}());
How do I achieve the same with Angular 2?