Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
48 lines (48 loc) · 1.99 KB
/
Copy pathmain.js
File metadata and controls
48 lines (48 loc) · 1.99 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
var app=angular.module("myApp",[]);
app.controller('appController',[function(){
var self=this;
self.items=[
{name: 'Computer', price: 500, condition:'New',brand : 'Lenovo', published:'01/11/2015'},
{name: 'Phone', price: 200, condition:'New',brand : 'Samsung', published:'02/11/2015'},
{name: 'Printer', price: 300, condition:'New',brand : 'Brother', published:'06/11/2015'},
{name: 'Dishwasher', price: 250, condition:'Second-Hand',brand : 'WhirlPool', published:'01/12/2015'}
];
self.onItemSelect=function(name){
console.log("congrats You have selected the item",name);
};
}]);
directive('itemWidget',[function(){
return{
restrict:'E',
replace:true,
transclude:true,
require:'^shoppingWidget',
scope:{
item='=',
promo='@',
pickMe:'&onSelect'
},
templateUrl:'shopItem.html',
link:function(scope,element,attrs,cartCtrl){
element.on('click',function(event){
element.htlm("Thanks for Purchasing this item");
element.css({color:green;});
cartCtrl.addItemToCart(scope.item);
scope.$apply();
});
}
}
}]);
directive('shoppingWidget',[function(){
return{
restrict:'E',
transclude:true,
templateUrl:'shopDetails.html',
scope:true,
controller:['$scope',function($scope){
$scope.cart=[];
var self=this;
self.addItemToCart=function(item){
$scope.cart.push(item);};}]
}
}]);