Skip to content

Commit 0f3d0d5

Browse files
committed
Adapter on controller demo
1 parent f13089e commit 0f3d0d5

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Adapter On Controller</title>
6+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js"></script>
7+
<script src="../../dist/ui-scroll.js"></script>
8+
<script src="../../dist/ui-scroll-jqlite.js"></script>
9+
<script src="adapterOnController.js"></script>
10+
<link rel="stylesheet" href="../css/style.css" type="text/css"/>
11+
</head>
12+
<body ng-controller="mainController" ng-app="application">
13+
14+
<div class="cont cont-global">
15+
16+
<a class="back" href="../index.html">browse other examples</a>
17+
18+
<h1 class="page-header page-header-exapmle">Adapter On Controller</h1>
19+
20+
<div class="description">
21+
There may be some nested scopes between the ui-scroll and the controller where you want the adapter object to be injected. As it follows from the documentation, <em>adapter="expression on controller"</em> format can be used to explicitly specify the scope associated with the specified controller as the target scope for the injection.
22+
<div class="code">
23+
<pre>&lt;div ui-scroll="item in datasource" adapter="adapter on mainController"&gt;{{item}<!---->}&lt;/div&gt;</pre>
24+
</div>
25+
In this sample we have ng-if wrapper over the viewport which causes an intermediate scope. "Is loading" will not work without specifying the controller through the "on controller" syntax .
26+
</div>
27+
28+
<div class="actions" ng-init="reloadIndex = 100">
29+
Is loading: {{adapter.isLoading}}
30+
</div>
31+
32+
<div ng-if="delay" class="viewport" id="viewport-serviceDatasource" ui-scroll-viewport>
33+
<div class="item" ui-scroll="item in datasource" adapter="adapter on mainController">{{item}}</div>
34+
</div>
35+
36+
</div>
37+
38+
</body>
39+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
angular.module('application', ['ui.scroll', 'ui.scroll.jqlite'])
2+
.controller('mainController', [
3+
'$scope', '$log', '$timeout', function ($scope, console, $timeout) {
4+
var datasource = {};
5+
6+
datasource.get = function (index, count, success) {
7+
$timeout(function () {
8+
var result = [];
9+
for (var i = index; i <= index + count - 1; i++) {
10+
result.push("item #" + i);
11+
}
12+
success(result);
13+
}, 100);
14+
};
15+
16+
$scope.datasource = datasource;
17+
18+
$scope.delay = false;
19+
$timeout(function() {
20+
$scope.delay = true;
21+
}, 500);
22+
23+
}
24+
]);

demo/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ <h1 class="page-header">Scroller Examples</h1>
109109
Adapter (updatable scroller)
110110
</a>
111111
</li>
112+
<li>
113+
<a href="adapterOnController/adapterOnController.html">
114+
Append on controller
115+
</a>
116+
</li>
112117
<li>
113118
<a href="append/append.html">
114119
Append and prepend sync demo

0 commit comments

Comments
 (0)