-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (48 loc) · 1.28 KB
/
app.js
File metadata and controls
54 lines (48 loc) · 1.28 KB
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
(function(){
'use strict'
var shoppingListModule = angular.module('ShoppingListCheck',[])
shoppingListModule.controller('toBuyController',toBuyController)
shoppingListModule.controller('alreadyBoughtController',alreadyBoughtController)
shoppingListModule.service('shoppingService',shoppingService)
alreadyBoughtController.$inject=['shoppingService']
toBuyController.$inject=['shoppingService']
function shoppingService(){
var service = this;
var toBuyList=
[
{name:'cookies',quantity:10},
{name:'chocolates',quantity:15},
{name:'butter',quantity:20},
{name:'bread',quantity:25},
{name:'peanut',quantity:5}
]
var boughtList=[];
service.getBoughtItems = function()
{
return boughtList;
}
service.getToBuyItems = function()
{
return toBuyList;
}
service.buyItem=function(index)
{
var itemIndex = toBuyList[index];
boughtList.push(itemIndex)
toBuyList.splice(itemIndex,1)
}
}
function alreadyBoughtController(shoppingService)
{
var bought = this;
bought.items = shoppingService.getBoughtItems();
}
function toBuyController(shoppingService)
{
var tobuy = this;
tobuy.buyItem = function(index){
shoppingService.buyItem(index);
}
tobuy.items = shoppingService.getToBuyItems();
}
})();