以pre-填充AngularJS应用远程数据的最佳方式 [英] The best way to pre-populate remote data in AngularJS app

查看:133
本文介绍了以pre-填充AngularJS应用远程数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的AngularJS应用程序,我需要检索远程REST端点静态数据的多个集合。这些数据集将在整个应用程序生命周期为静态查找列表中。我想所有这些名单在应用程序初始启动填充,并予以保留并提供给多个控制器。我想preFER不能动态地加载任何额外的数据,这个​​特定的应用程序的一个假设是,加载后,任何进一步的网络连接可能没一会儿可用。
它是确定采取初始打击,因为用户将通过反正看完第一页的静态内容poccupied $ P $。
我想使这个质量载荷初始运行的应用程序块的一部分,而这一切静态数据粘成连接到$ rootScope各种收藏(这将使这在其他地方提供)
什么是处理这一要求的最好方法是什么?

In my AngularJS app, I need to retrieve multiple collections of static data from remote REST endpoints. Those data collections will be used throughout the entire application life cycle as static lookup lists. I would like for all those lists to be populated upon the initial application startup, and to be retained and made available to multiple controllers. I would prefer not to load any additional data dynamically, as one of the assumptions for this particular app, is that, once loaded, any further network connections may not be available for a while. It is OK to take an initial hit, as the users will be preoccupied by reading a static content of the first page anyway. I was thinking of making this mass loading a part of the initial application run block, and stick all this static data into various collections attached to the $rootScope (which would make that available everywhere else) What is the best way to handle this requirement?

推荐答案

我的方法是使用一种服务(或服务的集合,我窝),并设置缓存,以真正<方式/ code>在 $ HTTP 获取功能。通过这种方式,服务可以传递到任何你想要的控制器,缓存有提供给你的结果,而不需要额外的HTTP请求。​​

The way I approach this is to use a service (or a collection of services I nest), and set caching to true in the $http get functions. This way the service can be passed into any controller you desire, having cached results available to you without the need for additional http requests.

我可以尝试把这个变成一个例子,如果你不清楚这个给你,让我知道。

I can try to put this into an example if this is unclear to you, let me know.

编辑:您可以等待第一次调用这个服务要做到这一点缓存,或做在用户加载应用,无论哪种方式是可能的。

edit: you can either wait for the first call to this service to do this caching, or do this on app load, either way is possible.

这篇关于以pre-填充AngularJS应用远程数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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