Skip to content

Commit 5b16a0e

Browse files
committed
new demo: angular 1.5 component and es6 class controller
1 parent eb54675 commit 5b16a0e

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

demo/index.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ <h1 class="page-header">Scroller Examples</h1>
119119
Inside the directive (+ "Controller as" syntax)
120120
</a>
121121
</li>
122+
<li>
123+
<a href="insideComponent/insideComponent.html">
124+
Inside the es6 component
125+
</a>
126+
</li>
122127
<li>
123128
<a href="adapterOnController/adapterOnController.html">
124129
Append on controller
@@ -153,7 +158,7 @@ <h1 class="page-header">Scroller Examples</h1>
153158
<a href="grid-layout-manipulations/grid-layout-manipulations.html">
154159
Grid layout manipulations
155160
</a>
156-
</li>
161+
</li>
157162
<li>
158163
<a href="grid-dnd-sort/grid-dnd-sort.html">
159164
Grid drag and drop sort, moveBefore
@@ -177,4 +182,4 @@ <h1 class="page-header">Scroller Examples</h1>
177182

178183
</div>
179184
</body>
180-
</html>
185+
</html>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Inside es6 component</title>
6+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.js"></script>
7+
<script src="../../dist/ui-scroll.js"></script>
8+
<script src="../../dist/ui-scroll-jqlite.js"></script>
9+
<script src="insideComponent.js"></script>
10+
<link rel="stylesheet" href="../css/style.css" type="text/css"/>
11+
</head>
12+
<body 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">Scroller inside ES6 Component</h1>
19+
20+
<div class="description">
21+
This sample demonstrates encapsulation of the ui-scroll directive inside some custom component (Angular 1.5+). The controller of this Component is implemented as ES6 class. Note that this demo might not work in old browsers which don't support ES6 classes.
22+
</div>
23+
24+
<my-component></my-component>
25+
26+
</div>
27+
28+
</body>
29+
</html>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(function(angular) {
2+
3+
class Ctrl {
4+
constructor($timeout) {
5+
this.timeout = $timeout;
6+
this.show = true;
7+
}
8+
9+
get(index, count, success) {
10+
this.timeout(function () {
11+
var result = [];
12+
for (var i = index; i <= index + count - 1; i++) {
13+
result.push({
14+
id: i,
15+
name: "item #" + i
16+
});
17+
}
18+
success(result);
19+
}, 100);
20+
}
21+
22+
update(id) {
23+
return this.scrollAdapter.applyUpdates(function(item) {
24+
if (item.id === id) {
25+
item.name += " *";
26+
}
27+
});
28+
}
29+
}
30+
31+
angular
32+
.module('application', ['ui.scroll', 'ui.scroll.jqlite'])
33+
.component('myComponent', {
34+
controllerAs: 'ctrl',
35+
template:
36+
'<div ui-scroll-viewport class="viewport" ng-if="ctrl.show">' +
37+
'<div class="item" ui-scroll="item in ctrl" adapter="ctrl.scrollAdapter">' +
38+
'<div ng-click="ctrl.update(item.id)">{{item.name}}</div>' +
39+
'</div>' +
40+
'</div>',
41+
controller: Ctrl
42+
});
43+
44+
})(angular);

0 commit comments

Comments
 (0)