0

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

5
  • Not clear what you are asking to do... What do you mean with "using $resource only with html"? Commented Feb 19, 2016 at 13:13
  • I mean to ask is, i want to access the products from the JSON array which i will select dynamically from veg,nonveg,rice. Commented Mar 4, 2016 at 6:37
  • A bit of your code (besides the JSON response) could be usefull... Commented Mar 4, 2016 at 9:27
  • 1
    I think you are sending an empty object, which is should be an array. So check once the code where you are doing it. Commented Apr 30, 2016 at 5:41
  • Thanks @ANK, I got it Commented Apr 30, 2016 at 5:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.