Here is code for Factories
LifeStyleFactoryMOdule.factory("PurchaseFactory",function(){
var productlist={products:[]};
return{
getpurchaseCart:function(){
return productlist;
},
addPurchaseCart:function(products){
productlist.products.push(products);
},
deletePurchase:function(idx){
productlist.products.splice(idx,1)
}
}
})
Services
LifeStyleServiceModule.service("PurchaseService",function(PurchaseFactory){
this.getAllPurchase=function(){
return PurchaseFactory.getpurchaseCart();
}
this.addPurchase=function(products)
{
PurchaseFactory.addPurchaseCart(products);
}
this.deletePurchase=function(idx,id)
{
PurchaseFactory.deletePurchase(idx,id);
}
})
Controllers having function
LifeStyleController.controller("PurchaseController",function($scopePurchaseService){
$scope.savepurchase=function(products){
if($scope.products._id==undefined){
$scope.products=angular.extend($scope.products,$scope.sizes)
PurchaseService.addPurchase($scope.products);
$scope.products={};
$scope.sizes={size:[]}
}
}
In HTML i having a button and all the data i am sending. First Time I push the data is is done successfully, but for second time its showing me error as productlist.products.push is not a function
Knowing answer will be great help