延迟角应用初始化 [英] Delay Angular App Initialization

查看:136
本文介绍了延迟角应用初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是在后台异步处理一些数据,并希望推迟整个角应用程序初始化直到完成。

I have some data that is being processed asynchronously in the background and want to delay the initialization of the entire Angular application until this finished.

BackgroundData.initialized是问答的诺言,所以是这样的:

BackgroundData.initialized is a Q promise, so something like this:

BackgroundData.initialized.then(AngularDoYoStuff)

我遇到的问题是在主页的控制器开始它的初始化程序,打BackgroundData,要么是有错误的/没有数据。

The problem I run into is the home page's controller starts its initialization procedure, hits BackgroundData and either it has the wrong/no data.

什么功能,我可以换角度的初始化中如此,而不是仅仅DOM就绪,就等待DOM准备和BackgroundData.initialization?

What function can I wrap Angular's initialization in so, instead of just dom-ready, it waits for both dom-ready and BackgroundData.initialization?

更新

我已经得到的文档更紧密的手动引导

I have gotten closer with the documentation on manual bootstrapping:

angular.element(document).ready ->
  setupGA()
  window.BackgroundData = new DataMachine()
  BackgroundData.initialized.then ->
    angular.bootstrap(document)

但是,当控制器负载文件(该文件之后),他们仍然得到BackgroundData之前初始化定义

But when the controller files load (after this file), they are still getting initialized before BackgroundData is defined

更新2

在HTML删除 NG-应用指令似乎已经解决了这一问题(因为这告诉角度自动初始化),但现在它只是忽略了我的全部 angular.module 要求

Removing the ng-app directive in the HTML seems to have fixed the problem (since that was telling Angular to auto-init) but now it just ignores all of my angular.module calls

推荐答案

问题是,我不得不留在HTML标记 NG-应用指令,它告诉角自动初始化范围。删除它让我手动初始化才能正确运行。

The problem was that I had left the ng-app directive in the html tag, which tells Angular to auto-initialize that scope. Removing it allowed my manual initialization to run correctly.

这篇关于延迟角应用初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆