【发布时间】:2016-07-10 20:35:59
【问题描述】:
excellent article 介绍了如何异步引导 angular1 应用程序。这使我们能够在引导之前从服务器获取 json。
主要代码在这里:
(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"]);
});
}
}());
如何使用 Angular 2 实现相同的目标?
【问题讨论】:
-
同理。 . .
-
所以我应该看看如何使用 angular2 注入器手动获取 http 客户端?
-
类似
new Injector([HTTP_PROVIDERS]).get(Http)