This repository was archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeferred-initialization-timeout.html
More file actions
72 lines (62 loc) · 2.23 KB
/
deferred-initialization-timeout.html
File metadata and controls
72 lines (62 loc) · 2.23 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Deferred Initialization with Timeout — ($)QOrlate Example</title>
<script src="https://code.angularjs.org/1.3.9/angular.min.js"></script>
<script src="../release/jlikness.qorlate.min.js"></script>
</head>
<body>
<div ng-app="example1">
<ul>
<li>First</li>
<li ng-repeat="num in list1">{{num}}</li>
</ul>
<ul>
<li>Second</li>
<li ng-repeat="num in list2">{{num}}</li>
</ul>
</div>
<script type="text/javascript">
(function (app) {
// emulate a service that must asynchronously
// build a list before it can start satisfying
// requests, and have one request reject before
// it can be satisfied
function ListService(qorlate, $timeout) {
var _this = this;
this.qorlate = qorlate;
$timeout(function () {
_this.list = [1, 2, 3, 4, 5];
_this.qorlate.resolve(_this.id, _this.list);
}, qorlate.defaultTimeout + 100);
}
angular.extend(ListService.prototype, {
id: (new Date ()).getTime(),
list: [],
getList: function () {
return this.qorlate({ id: this.id }).promise;
}
});
app.service('listService', ListService);
app.run(['$timeout', '$rootScope', 'listService', 'qorlate',
function (t, rs, ls, q) {
rs.list1 = [];
rs.list2 = [];
// request before it's ready
ls.getList().then(function (data) {
rs.list1 = data;
}, function (err) {
rs.list1.push(err.message);
});
// request after it's ready
t(function () {
ls.getList().then(function (data) {
rs.list2 = data;
});
}, q.defaultTimeout + 200);
}]);
})(angular.module('example1', ['jlikness.qorlate']));
</script>
</body>
</html>