博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AngularJS 无限滚动加载数据控件 ngInfiniteScroll
阅读量:4096 次
发布时间:2019-05-25

本文共 2224 字,大约阅读时间需要 7 分钟。

链接:http://blog.csdn.net/soaring_tiger/article/details/43954401

 

1、什么是 InfiniteScroll? 

无限滚动(Infinite Scroll)也称为自动分页、滚动分页和无限分页。常用在图片、文章或其它列表形式的网页中,用来在滚动网页到页面底部的时候自动加载下一页的内容。 
这种形式最早由推特(twitter)使用,后来必应图片搜索、谷歌图片搜 索、google reader等纷纷采用了这一项技术,于是靠滚动浏览器滚动条来翻页的技术慢慢在互联网上遍站开花。该技术非常适合移动端的数据自动加载。

2、什么是ngInfiniteScroll? 

ngInfiniteScroll 是用于 的无限滚动控件,特点是简单易用,是AngularJS社区里应用最为广泛的”触底加载”控件。

3、如何使用ngInfiniteScroll? 

只要以下4步就可以搞定ngInfiniteScroll :

<1>引用javascript文件(注意把js加载顺序)
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3
<2>声明对 ***infinite-scroll***的依赖
angular.module('myApplication', ['infinite-scroll']);
  • 1
  • 1
<3>在html页面使用 infinite-scroll 元素
  • 1
  • 1
<4>ok,调用你的分页函数 myPagingFunction(),开始使用吧。使用细节参考[ngInfiniteScroll API文档](http://sroze.github.io/ngInfiniteScroll/documentation.html)。下附例子:[ngInfiniteScroll 动态加载实例](http://sroze.github.io/ngInfiniteScroll/demo_async.html)

HTML代码:

{
{
item.score}}
{
{
item.title}}
by {
{
item.author}} - {
{
item.num_comments}} comments
Loading data...

 代码(自动加载 Reddit):

var myApp = angular.module('myApp', ['infinite-scroll']);myApp.controller('DemoController', function($scope, Reddit) {  $scope.reddit = new Reddit();});// Reddit constructor function to encapsulate HTTP and pagination logicmyApp.factory('Reddit', function($http) {  var Reddit = function() {    this.items = [];    this.busy = false;    this.after = '';  };  Reddit.prototype.nextPage = function() {    if (this.busy) return;    this.busy = true;    var url = "http://api.reddit.com/hot?after=" + this.after + "&jsonp=JSON_CALLBACK";    $http.jsonp(url).success(function(data) {      var items = data.data.children;      for (var i = 0; i < items.length; i++) {        this.items.push(items[i].data);      }      this.after = "t3_" + this.items[this.items.length - 1].id;      this.busy = false;    }.bind(this));  };  return Reddit;});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

特别提醒: 

容易犯的错误,把ng-repeat标签和infinite-scroll放在同一个

标签下:

 

{
{
item}}
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4
{
{
item}}

 

你可能感兴趣的文章
通过mavlink实现自主航线的过程笔记
查看>>
Flutter Boost的router管理
查看>>
每个人都能做的网易云音乐[vue全家桶]
查看>>
Vue2.0全家桶仿腾讯课堂(移动端)
查看>>
React+Redux系列教程
查看>>
19 个 JavaScript 常用的简写技术
查看>>
iOS开发 支付之银联支付集成
查看>>
iOS开发支付集成之微信支付
查看>>
浅谈JavaScript--声明提升
查看>>
React非嵌套组件通信
查看>>
Websocket 使用指南
查看>>
浏览器兼容性问题解决方案 · 总结
查看>>
一个很棒的Flutter学习资源列表
查看>>
为什么你应该放弃React老的Context API用新的Context API
查看>>
Koa2初体验
查看>>
Koa 2 初体验(二)
查看>>
Koa2框架原理解析和实现
查看>>
vue源码系列文章good
查看>>
你不知道的Virtual DOM
查看>>
VUE面试题总结
查看>>