0

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

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

1 Answer 1

1

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;
}

});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot Shubhan ,for this help , My issue solved
Upvote and validate answer and keep helping others as well.. :)
while receiving in Spring Controller we have to use PostMapping along with RequestBody ?

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.