在angularjs初始数据加载 [英] initial data loading in angularjs

查看:177
本文介绍了在angularjs初始数据加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在构建Web应用程序,每一个页面取决于多种数据源,什么是获取数据的初始位的最佳方法是什么?当我看微博,我看到,可见在页面加载的鸣叫是在HTML代码中,更多的鸣叫在使用AJAX,你向下滚动加载。但是,没有任何方便的方式来获得的数据是已经在DOM要插入到模型中。

When building a web app where every page depends on many data sources, what's the best way to fetch the initial bits of data? When I look at twitter, I see the tweets that are visible on page load are in the HTML source, and more tweets are loaded in using AJAX as you scroll down. But there's no convenient way to get data that's already in the DOM to be inserted into the model.

庄家对初始数据的请求,页面加载接缝愚蠢后,因为你刚刚做了很多的往返到服务器,以获取CSS,HTML和JavaScript。难道是一个坏主意,将数据插入到页面上的javascript标记,这样一个JavaScript函数可以添加的初始数据?

Making a request for the initial data, immediately after page load seams stupid, because you've just made a lot of roundtrips to the server to fetch css, html and javascript. Would it be a bad idea to insert the data into a javascript tag on the page, so a javascript function can add the initial data?

我专门要求angularjs,但如果有一个通用的技术,请让我知道为好。

I'm specifically asking for angularjs, but if there's an general technique, please let me know as well.

推荐答案

您会反正在页面加载引用您的控制器,所以你不会有有一个内嵌的脚本。

You'll be referencing your controller anyway on page load, so you won't have to have an inline script tag.

您可以设置一个默认的模型,并使用属性 NG绑定在初始加载或调用一个函数来传回数据。

You can either set a default model and use the attribute ng-bind on initial load, or call a function to pass back data.

这是pretty的典型,以获取在angularjs上加载数据。

It's pretty typical to fetch data on load in angularjs.

这篇关于在angularjs初始数据加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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