So booten Sie eine Angular 2-Anwendung asynchron
Da ist einAusgezeichneter Artikel, wie eine angle1-Anwendung asynchron gebootet wird. Auf diese Weise können wir vor dem Bootstrapping einen JSON-Code vom Server abrufen.
Der Hauptcode ist hier:
(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"]);
});
}
}());
Wie erreiche ich dasselbe mit Angular 2?