-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
74 lines (68 loc) · 2.17 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
(function(){
'use strict'
var ShoppingListItems=[
{name:"Cookies",quantity:"10"},
{name:"Bottles",quantity:"5"},
{name:"Cakes",quantity:"4"},
{name:"Pizza",quantity:"3"},
{name:"Burgers",quantity:"8"}
]
angular.module('ShoppingListCheckOff',[])
.controller('ToBuyController',ToBuyController)
.controller('AlreadyBoughtController',AlreadyBoughtController)
.service("ShoppingListCheckOffService",ShoppingListCheckOffService);
//To Buy Controller
ToBuyController.$inject=['ShoppingListCheckOffService'];
function ToBuyController(ShoppingListCheckOffService){
var buyCont=this;
buyCont.itemIndex=0;
var shoppingService=ShoppingListCheckOffService;
buyCont.getBuyList=function (){
var list= shoppingService.getBuyList();
if(list.length===0){
buyCont.Status="Everything is bought!";
}
else{
buyCont.Status="";
}
return list;
}
buyCont.buyItem=function(indexItem){
shoppingService.buyItem(indexItem);
};
}
// Already Bought Controller
AlreadyBoughtController.$inject=['ShoppingListCheckOffService'];
function AlreadyBoughtController(ShoppingListCheckOffService){
var boughtCont=this;
var shoppingService =ShoppingListCheckOffService;
boughtCont.getboughtList=function(){
var list=shoppingService.getBoughtList();
if(list.length===0){
boughtCont.Status="Nothing bought yet.";
}
else{
boughtCont.Status="";
}
return list;
}
}
//Service
function ShoppingListCheckOffService(){
var service=this;
var toBuyItems=[];
toBuyItems=ShoppingListItems;
var boughtItems=[];
service.buyItem=function(itemIndex){
var value=toBuyItems[itemIndex];
boughtItems.push(value);
toBuyItems.splice(itemIndex,1);
};
service.getBuyList=function(){
return toBuyItems;
}
service.getBoughtList=function(){
return boughtItems;
}
}
})();