Es gibt eine excellent article, wie Sie eine angular1-Anwendung asynchron starten. Dadurch können wir vor dem Bootstrapping einen json vom Server holen.So können Sie eine Angular 2-Anwendung asynchron starten
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 das gleiche mit kantigem 2?
auf die gleiche Weise. . . –
also sollte ich nur schauen, wie man den http client manuell mit dem angular2 injektor bekommt? –
etwas wie 'neuer Injektor ([HTTP_PROVIDERS]). Get (Http)' –