Angular 2 app初始化

时间:2017-03-10 22:29:46

标签: angular

我是Angualr 2和RxJS(来自Angular 1.x)的新手,我正在努力正确地初始化应用程序。

以下是该方案。我的应用程序在初始化时需要来自服务器的一些数据。我正在考虑从AppModule的构造函数进行http调用以检索此数据,填充将保存此数据的服务,然后继续加载应用程序。

实现这一目标的最佳方法是什么?

我尝试使用:

export class AppModule {
	constructor(http: Http, common: CommonService) {
		http.get('config').map(res => res.json()).do((cfg) => {
			common.config = cfg;
		});
	}
}

但do(...)中的代码永远不会执行。

感谢。

0 个答案:

没有答案