如何执行所有“on load”所有控制器的承诺一下子 [英] How do I execute all "on load" promises from all controllers at once

查看:53
本文介绍了如何执行所有“on load”所有控制器的承诺一下子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的情况是我的许多控件都有自己的控制器功能,即使是masterCtrl(在母版页上)



所以我需要显示我的启动,直到每个控制器都通过异步承诺完成加载数据。



我可以相当很容易将所有承诺传递给masterCtrl,它可以执行所有并在完成时关闭启动。



我的问题是如何知道何时执行承诺数组? masterCtrl(永远是子控制器的父节点)如何知道它具有所有的承诺?



哦,并且所有控制器都挂在同一个masterApp模块中。



我尝试了什么:



我目前正在等待要加载的页面:



Hi,

I have a situation where many of my controls have their own controller functions, even the masterCtrl (on the master page)

So I need to display my splash until each and every controller has finished loading data via async promises.

I could quite easily pass all promises up to the masterCtrl which could execute all and close the splash on completion.

My issue is how do I know when to execute the array of promises? How does masterCtrl (which will always be the parent of the sub controllers) know that it has all the promises?

Oh, and all controllers hang of the same masterApp module.

What I have tried:

I currently wait for the page to load:

angular.element(document).ready(function () {
    promise.all($scope.promised).then(()=>$scope.splash.close())
})





但我不知道这是否仅在控制器准备就绪后触发,或者它已经足够晚,控制器无论如何都在平均时间加载,我可能会有第二次超时。我对这些事件如何联系起来一无所知



but I don't know if this triggers only after the controllers are ready, or if it's just late enough that the controllers have loaded in the mean time anyway and I might as well have a second timeout instead. I am clueless as to how these events tie together

推荐答案

scope.promised).then(()=>
scope.promised).then(()=>


scope.splash.close())
})
scope.splash.close()) })





但我不知道这是否触发只有在控制器准备就绪之后,或者如果它已经足够晚以至于控制器无论如何都在平均时间内加载,而我可能还有第二次超时。关于这些事件如何结合起来,我一无所知



but I don't know if this triggers only after the controllers are ready, or if it's just late enough that the controllers have loaded in the mean time anyway and I might as well have a second timeout instead. I am clueless as to how these events tie together


这篇关于如何执行所有“on load”所有控制器的承诺一下子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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