Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I added list of item value store in array, how do I pass angular array list to controller.

$scope.AddRecord = [];

$scope.AddUpdateItem = function (item_id, item_discription, item_quantity, item_unit, item_rate, item_discount) {

    var getItemAction = $scope.Action;

    if (getItemAction == "Update") {

        $scope.AddRecord[key].budget_item_id = item_id;
        $scope.AddRecord[key].budget_item_discription = item_discription;
        $scope.AddRecord[key].budget_item_quantity = item_quantity;
        $scope.AddRecord[key].budget_item_unit = item_unit;
        $scope.AddRecord[key].budget_item_rate = item_rate;
        $scope.AddRecord[key].budget_item_discount = item_discount; 

        $scope.divItem = false; 
        ClearFields();
    } else
    {  
        $scope.AddRecord.push({ 'budget_item_id': $scope.item_id, 'budget_item_discription': $scope.item_discription, 'budget_item_quantity': $scope.item_quantity, 'budget_item_unit': $scope.item_unit, 'budget_item_rate': $scope.item_rate, 'budget_item_discount': $scope.item_discount });
        ClearFields();
    }
    }

I added list of item value store in array but i am not able pass list to controller,so please somebody help me how to pass angular array list to controller

share|improve this question
    
do you want to pass it another controller or want to use within – Shubham Nigam Mar 2 '16 at 5:53
1  
thanks for replay i want to pass my asp.net mvc controller because i need store value in database – dinesh patidar Mar 2 '16 at 5:58
    
please have a look .. are you looking for this.. stackoverflow.com/questions/9293423/… – Shubham Nigam Mar 2 '16 at 5:59
    
ok ,i seen this link, but i don't understand how to post array list values on serverside – dinesh patidar Mar 2 '16 at 6:11
    
then you need to use $http service to post data to server. – Shubham Nigam Mar 2 '16 at 6:12

As far as I understood you ,please have a look on it and let me know if you still face some issue

 $scope.AddUpdateItem = function (item_id, item_discription, item_quantity, item_unit, item_rate, item_discount) {

        var getItemAction = $scope.Action;

        if (getItemAction == "Update") {

            $scope.AddRecord[key].budget_item_id = item_id;
            $scope.AddRecord[key].budget_item_discription = item_discription;
            $scope.AddRecord[key].budget_item_quantity = item_quantity;
            $scope.AddRecord[key].budget_item_unit = item_unit;
            $scope.AddRecord[key].budget_item_rate = item_rate;
            $scope.AddRecord[key].budget_item_discount = item_discount; 

            $scope.divItem = false; 
            ClearFields();
        } else
        {  
            var item = { 'budget_item_id': $scope.item_id, 'budget_item_discription': $scope.item_discription, 'budget_item_quantity': $scope.item_quantity, 'budget_item_unit': $scope.item_unit, 'budget_item_rate': $scope.item_rate, 'budget_item_discount': $scope.item_discount }
            $scope.AddRecord.push(item);
            myService.addItem(item);//call service to send data to server
            ClearFields();
        }
        }

Service

myapp.service('myService',function($http){

    this.additem = function (item) { 
       var response = $http({ 
             method: "post", 
             url: '/Budget/AddBudgetItem', 
             data: JSON.stringify(item),
             dataType: "json" 
     }); 
     return response;
}

});
share|improve this answer
    
Thanks a lot Shubhan ,for this help , My issue solved – dinesh patidar Mar 2 '16 at 6:49
    
Upvote and validate answer and keep helping others as well.. :) – Shubham Nigam Mar 2 '16 at 6:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.