如何延迟AngularJS App初始化? [英] How to delay AngularJS App Initialization?
问题描述
我有一些正在后台异步处理的数据,并希望将整个AngularJS应用程序的初始化延迟到完成为止.
I have some data that is being processed asynchronously in the background and want to delay the initialization of the entire AngularJS application until this finished.
BackgroundData.initialized是一个Q承诺,所以像这样:
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.
我可以用什么功能包装Angular的初始化,而不是只准备dom,而是要等待dom和背景数据初始化?
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-app
指令似乎已经解决了该问题(因为这告诉Angular自动初始化),但是现在它只是忽略了我所有的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-app
指令,该指令告诉Angular自动初始化该范围.删除它可以使我的手动初始化正确运行.
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.
这篇关于如何延迟AngularJS App初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!