-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (62 loc) · 1.61 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
(function () {
'use strict';
angular.module('ShoppingListCheckOff', [])
.controller('ToBuyController', ToBuyController)
.controller('AlreadyBoughtController', AlreadyBoughtController)
.service('ShoppingListCheckOffService', ShoppingListCheckOffService);
// LIST #1 - controller
ToBuyController.$inject = ['ShoppingListCheckOffService'];
function ToBuyController(ShoppingListCheckOffService) {
var list1 = this;
list1.shoppingList = ShoppingListCheckOffService.getItems();
//console.log(list1.shoppingList);
list1.removeItem = function (itemIndex) {
ShoppingListCheckOffService.removeItem(itemIndex);
};
}
// LIST #2 - controller
AlreadyBoughtController.$inject = ['ShoppingListCheckOffService'];
function AlreadyBoughtController(ShoppingListCheckOffService) {
var list2 = this;
// Use factory to create new shopping list service
list2.bought = ShoppingListCheckOffService.getbought();
console.log(list2.bought);
}
function ShoppingListCheckOffService(){
var service = this;
var toBuyItems=[
{
name: "Milk",
quantity: "2"
},
{
name: "Donuts",
quantity: "200"
},
{
name: "Cookies",
quantity: "300"
},
{
name: "Chocolate",
quantity: "5"
},
{
name: "Chocolate Milk",
quantity: "50"
}
];
var boughtitems=[];
service.getItems= function(){
return toBuyItems;
}
service.removeItem = function (itemIndex) {
var item=toBuyItems.splice(itemIndex, 1);
console.log(item[0]);
boughtitems.push(item[0]);
};
service.getbought = function () {
return boughtitems;
};
}
})();