-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (36 loc) · 1.2 KB
/
app.js
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
require([
"angular",
"delite/register",
"deliteful/list/List",
"angular-delite/wrappers/widget",
"angular-delite/dstore/TrackableRest"
], function (angular, register, List, wrapper) {
angular.module("app", ["dstore.trackableRest"])
// creating a trackable REST store as a service
.factory("BookList", function (TrackableRest) {
return new TrackableRest({target: "http://nonews.mybluemix.net/book/"});
})
// creating directive <ng-list ... ></ng-list>
.directive("ngList", ["BookList", function (BookList) {
return wrapper(List, {selectedItems: "="}, {
store : BookList,
labelAttr : "title",
idAttr : "id",
righttextFunc : function (item) { return "ISBN " + item.isbn; }
});
}])
.controller("MainCtrl", ["$scope", function ($scope) {
$scope.add = function (newTitle, newISBN) {
$scope.books.store.add({title: newTitle, isbn: newISBN});
};
$scope.removeSelected = function () {
$scope.selectedItems.forEach(function (item) {
$scope.books.store.remove(item.id);
});
};
}]);
// boostrapping
angular.element(document).ready(function () {
angular.bootstrap(document, ["app"]); // start angular
});
});