AngularJS - 加载任何控制器之前加载数据 [英] AngularJS - load data before loading any controller
问题描述
我正在做一个单页的应用程序(SPA)。我做了一个名为 InitialControler
控制器在此URL(local.app/init)加载来自服务器的数据。
I'm making a single page application (SPA). I made a controller called InitialControler
to load the data from the server at this url (local.app/init).
我想这个网址到任何其他的URL,然后打开。我使用的UI路由器,我在 .RUN()$ C $做了一个
$ state.go('初始化')
C>功能,但它仍然加载初始化
页面之前请求的页面
I want this url to be opened before any other url. I'm using ui-router, I did a $state.go('init')
in the .run()
function but it still load the requested page before the 'init'
page
推荐答案
做的一个方法是,在配置声明只有初始化状态。而在InitialController,数据被加载(服务调用的决心功能)后,配置其他国家。但是,在这种方法中,每当您刷新页面,URL将变为local.app.init。
One way to do is, in config declare only 'init' state. And in InitialController, after data is loaded(resolve function of service call), configure other states. But in this approach, whenever you refresh the page, the url will change to local.app.init.
要留在那个特定的状态,即使重装后,我找到了解决方法是在其中我装所需的数据之后,我通过angular.bootstrap手动bootstraped主要的应用程序启动的应用程序。
To stay in that particular state even after reloading, the solution I found is to have a StartUp app in which I loaded the required data and after that I bootstraped the main app manually by angular.bootstrap.
这篇关于AngularJS - 加载任何控制器之前加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!