-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
107 lines (67 loc) · 1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(function () {
'use strict';
angular.module('shoppingApp', [])
.controller('ToBuyController', ToBuyController)
.controller('AlreadyBoughtController', AlreadyBoughtController)
.service('ShoppingListService', ShoppingListService);
ToBuyController.$inject = ['ShoppingListService'];
function ToBuyController(ShoppingListService) {
var toBuy = this;
toBuy.showList= ShoppingListService.showBuyList();
toBuy.show = 0;
toBuy.Update = function(index){
ShoppingListService.ListBoughtItems_adder(index);
ShoppingListService.ListToBuyItems_remover(index);
toBuy.show = ShoppingListService.ToBuyShow();
};
}
AlreadyBoughtController.$inject = ['ShoppingListService','$scope'];
function AlreadyBoughtController(ShoppingListService,$scope) {
var bought=this;
bought.showList = ShoppingListService.showBoughtList();
bought.hide = 1;
$scope.$watch(function(){
bought.hide = ShoppingListService.BoughtShow();
});
}
function ShoppingListService() {
var service = this;
var toBuyItems = [{name:'chicken',quantity:2},{name:'banana',quantity:3},{name:'apple',quantity:5},{name:'soup',quantity:1},{name:'water',quantity:5},{name:'poop',quantity:10}];
var boughtItems = [];
var counter = 0 ;
var sizeOfArray = toBuyItems.length;
service.ListBoughtItems_adder = function(index){
counter++;
var item = {
name: toBuyItems[index].name,
quantity: toBuyItems[index].quantity,
counter :counter
};
boughtItems.push(item);
service.ToBuyShow();
};
service.ListToBuyItems_remover = function(index){
toBuyItems.splice(index,1);
};
service.showBuyList = function(){
return toBuyItems;
};
service.showBoughtList = function(){
return boughtItems;
};
service.ToBuyShow= function(){
if(toBuyItems.length==0){
return 1;
}else{
return 0;
}
};
service.BoughtShow= function(){
if(toBuyItems.length == 6){
return 1;
}else{
return 0;
}
};
}
})();