【发布时间】:2015-04-20 23:09:13
【问题描述】:
我正在处理 angularJs 和 typescript 项目。在启动客户端应用程序并加载 UI 之前,我必须进行同步 http 调用并从服务器获取一些数据。我在互联网上搜索,看到每个人都在谈论承诺,嗯,好吧,为什么不呢。所以我在我的 app.run() 中使用了 Promise(调用 $http 并使用 $q 返回 Promise)。也许我什么都没有,因为这根本不起作用。 Angular 启动 app.config(),然后 app.run(),... 但是 Angular 在启动 app.run() 之前不会等待 app.config() 完成。所以我的第一个承诺是在 app.run() 中启动,在它解决 Angular 之前尝试实例化控制器......我不想创建新的服务调用 httpSynchronous 但我没有任何其他想法。
【问题讨论】:
-
请更新一些代码:D
-
你能把http同步调用移到你的app.run吗?然后,您可以使用取决于结果的代码进入成功块。
标签: javascript angularjs promise synchronous