-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (40 loc) · 1.36 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
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
(function(){
'use strict';
angular.module('ShoppingListCheckOff', [])
.controller('ToBuyController', ToBuyController)
.controller('AlreadyBoughtController', AlreadyBoughtController)
.service('ShoppingListCheckOffService', ShoppingListCheckOffService);
ToBuyController.$inject = ['ShoppingListCheckOffService'];
function ToBuyController(ShoppingListCheckOffService) {
var buyList = this;
buyList.items = ShoppingListCheckOffService.getBuyItems();
buyList.moveItem = function(itemIndex) {
ShoppingListCheckOffService.moveItem(itemIndex);
}
}
AlreadyBoughtController.$inject = ['ShoppingListCheckOffService'];
function AlreadyBoughtController(ShoppingListCheckOffService) {
var boughtList = this;
boughtList.items = ShoppingListCheckOffService.getBougthItems()
}
function ShoppingListCheckOffService() {
var service = this;
var buyItems = [{name: 'cookies', quantity: 10},
{name: 'chips', quantity: 5},
{name: 'vodka', quantity: 8},
{name: 'beer', quantity: 10},
{name: 'cannabis', quantity: 15}];
var boughtItems = [];
service.getBuyItems = function() {
return buyItems;
}
service.getBougthItems = function() {
return boughtItems;
}
service.moveItem = function(itemIndex) {
var movingItem = buyItems[itemIndex];
buyItems.splice(itemIndex, 1);
boughtItems.push(movingItem);
}
}
})();