Skip to content

Commit 3832dae

Browse files
committed
Controller As demo
1 parent fc623ed commit 3832dae

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

demo/controllerAs/controllerAs.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!doctype html>
2+
<html ng-app="application">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Scroller Demo (controller as)</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="controllerAs.js"></script>
10+
<link rel="stylesheet" href="../css/style.css" type="text/css"/>
11+
12+
13+
</head>
14+
<body ng-app="application">
15+
16+
<div class="cont cont-global" ng-controller="mainController as mainCtrl" ng-init="show = true">
17+
<a class="back" href="../index.html">browse other examples</a>
18+
<h1 class="page-header page-header-exapmle">Controller as syntax for the Datasource and the Adapter</h1>
19+
<div class="description">
20+
If you have defined your controller in such way
21+
<div class="code">
22+
<pre>&lt;div ng-controller="mainController as mainCtrl"&gt;</pre>
23+
</div>
24+
then you just shouldn't miss it when you define your datasource or adapter:
25+
<div class="code">
26+
<pre>&lt;div ui-scroll="item in mainCtrl.datasource" adapter="mainCtrl.adapter"&gt;{{item}<!---->}&lt;/div&gt;</pre>
27+
</div>
28+
"Hide/Show" button provides a nested scope between mainController and the Viewport via ng-if directive.
29+
</div>
30+
31+
<div class="actions">
32+
<button ng-click="show = !show">{{!show ? 'Show' : 'Hide'}}</button>
33+
<button ng-click="mainCtrl.updateList()">Update</button>
34+
</div>
35+
36+
<div class="info">
37+
<span ng-hide="mainCtrl.adapter.isLoading">data has been loaded</span>
38+
<span ng-hide="!mainCtrl.adapter.isLoading">data loading...</span>
39+
</div>
40+
41+
<div ng-if="show">
42+
<div ui-scroll-viewport class="viewport viewport-height-fixed" id="viewport-adapter1">
43+
<div class="item" ui-scroll="item in mainCtrl.datasource"
44+
adapter="mainCtrl.adapter"
45+
buffer-size='5'>{{item.content}}</div>
46+
</div>
47+
</div>
48+
</div>
49+
50+
</body>
51+
</html>

demo/controllerAs/controllerAs.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
angular.module('application', ['ui.scroll', 'ui.scroll.jqlite']).controller('mainController', [
2+
'$timeout', function($timeout) {
3+
4+
var datasource = {};
5+
6+
datasource.get = function(index, count, success) {
7+
return $timeout(function() {
8+
var i, item, j, ref, ref1, result;
9+
result = [];
10+
for (i = j = ref = index, ref1 = index + count - 1; ref <= ref1 ? j <= ref1 : j >= ref1; i = ref <= ref1 ? ++j : --j) {
11+
item = {};
12+
item.id = i;
13+
item.content = "item #" + i;
14+
result.push(item);
15+
}
16+
return success(result);
17+
}, 100);
18+
};
19+
20+
this.datasource = datasource;
21+
22+
this.updateList = function() {
23+
this.adapter.applyUpdates(function(item, scope) {
24+
item.content += ' *';
25+
});
26+
};
27+
28+
}
29+
]);

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="controllerAs/controllerAs.html">
114+
controllerAs syntax
115+
</a>
116+
</li>
112117
<li>
113118
<a href="adapterOnController/adapterOnController.html">
114119
Append on controller

0 commit comments

Comments
 (0)