Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 58d49b7

Browse files
committed
infinite scroll example
1 parent 4c0aff2 commit 58d49b7

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

docs/assets/demo.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var app = angular.module('demo', ['ngSanitize', 'ui.select']);
3+
var app = angular.module('demo', ['ngSanitize', 'ui.select', 'ui.scrollpoint']);
44

55
/**
66
* AngularJS default filter with the following expression:
@@ -212,6 +212,32 @@ app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) {
212212
}
213213
}
214214

215+
vm.infinity = {
216+
cursor: 0, // start from (limitTo begin parameter requires angular >= 1.4.0)
217+
count: 10, // starting count
218+
limit: 10, // how many to show per load
219+
loading: false, // loading state
220+
more: function(distance, element, edge) {
221+
if (distance < 0 && (edge || element[0].offsetTop) && !$scope.infinity.loading) {
222+
// make sure we won't exceed the bounds
223+
if (($scope.infinity.cursor + $scope.infinity.count) < $scope.countries.length) {
224+
$scope.infinity.loading = true;
225+
$scope.$apply(); // infinity.more is triggered by non-angular window scroll event
226+
227+
// using a $timeout for demo purposes (this would typically be some async call to load more resources)
228+
$timeout(function(){
229+
$scope.infinity.loading = false;
230+
$scope.infinity.count += $scope.infinity.limit;
231+
var overflow = ($scope.infinity.cursor + $scope.infinity.count) - $scope.countries.length;
232+
if(overflow > 0){
233+
$scope.infinity.count -= overflow;
234+
}
235+
}, 500);
236+
}
237+
}
238+
}
239+
};
240+
215241
vm.country = {};
216242
vm.countries = [ // Taken from https://gist.github.com/unceus/6501985
217243
{name: 'Afghanistan', code: 'AF'},
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<h3>Basic Header and Footer</h3>
2+
<p>Selected: {{ctrl.address.selected.formatted_address}}</p>
3+
<ui-select ng-model="ctrl.address.selected"
4+
theme="bootstrap"
5+
ng-disabled="ctrl.disabled"
6+
reset-search-input="false"
7+
style="width: 300px;"
8+
title="Choose an address">
9+
<ui-select-match placeholder="Enter an address...">{{$select.selected.formatted_address}}</ui-select-match>
10+
<ui-select-header><h4>Simple Header</h4></ui-select-header>
11+
<ui-select-choices repeat="address in ctrl.addresses track by $index"
12+
refresh="refreshAddresses($select.search)"
13+
refresh-delay="0">
14+
<div ng-bind-html="address.formatted_address | highlight: $select.search"></div>
15+
</ui-select-choices>
16+
<ui-select-footer><strong>Simple Footer</strong></ui-select-footer>
17+
</ui-select>
18+
19+
<h3>Infinite Scrolling</h3>
20+
<p>Selected: {{ctrl.country.selected.name}}</p>
21+
<ui-select ng-model="ctrl.country.selected"
22+
theme="bootstrap"
23+
ng-disabled="ctrl.disabled"
24+
style="width: 300px;"
25+
title="Choose a country">
26+
<ui-select-match placeholder="Select a country from the list...">{{$select.selected.name}}</ui-select-match>
27+
<ui-select-choices repeat="country in ctrl.countries | limitTo : ctrl.infinity.count : ctrl.infinity.cursor" ui-scrollpoint-target>
28+
<span ng-bind-html="country.name | highlight: $select.search"></span>
29+
<small ng-bind-html="country.code | highlight: $select.search"></small>
30+
</ui-select-choices>
31+
<ui-select-footer>
32+
<div ng-show="ctrl.infinity.loading" class="spinner">Loading more countries...</div>
33+
<span ui-scrollpoint ui-scrollpoint-enabled="{{!ctrl.infinity.loading}}" ui-scrollpoint-edge="'bottom'" ui-scrollpoint-action="ctrl.infinity.more"></span>
34+
</ui-select-footer>
35+
</ui-select>

0 commit comments

Comments
 (0)