0

Hi i need to get input values from ng-repeat, i am having Item class like as follows

public class Item
{
    private String _DesignId;

    public String DesignId
    {
        get { return _DesignId; }
        set { _DesignId = value; }
    }
    private String _DesignName;

    public String DesignName
    {
        get { return _DesignName; }
        set { _DesignName = value; }
    }

    private String _Unit;

    public String Unit
    {
        get { return _Unit; }
        set { _Unit = value; }
    }

    private String _Price;

    public String Price
    {
        get { return _Price; }
        set { _Price = value; }
    }
}

Here my angularjs

 $scope.saveAllValues = function() {
   $scope.mylist = {};
   angular.forEach($scope.invoice.items , function(value, key){
   var objclsu = { 
   "DesignId" : value.DesignId,
   "DesignName" : $scope.ctrl.DesignName,
   "Unit" : value.unit,
   "Price" : value.price,
  };  
    $scope.mylist.push({objclsu});
});

Here I can not use push. objclsu is not an array. Here how to add objclsu into $scope.mylist.

Here my web method i am using generic list as a parameter

    [WebMethod()]
    public static void SaveList(List<Item> mylist)
    {  
    }


    var httpreq = { 
    method: 'POST', 
       url: 'Requirementapi/SaveList', 
   headers: { 'Content-Type': 'application/json; charset=utf-8', 'dataType': 'json' }, 
      data: { mylist : $scope.mylist } 
  } 
  $http(httpreq).success(function (response) { 
    callmsg(" invoice Saved successfully."); 
 });
Prakasam
  • 9
  • 2
  • `$scope.mylist = {};` creates an empty object. What you want is `$scope.mylist = [];`. – Lex Jan 18 '19 at 19:14
  • $scope.mylist = [] it will return empty value for all property in my SaveList(List mylist) – Prakasam Jan 18 '19 at 19:17
  • Even after you've pushed objects onto it? – Lex Jan 18 '19 at 19:19
  • $scope.mylist = []; $scope.mylist.push({objclsu}); it will return empty on web method – Prakasam Jan 18 '19 at 19:22
  • How are you calling the web method? You haven't shown that code. – Lex Jan 18 '19 at 19:23
  • var httpreq = { method: 'POST', url: 'Requirement.aspx/SaveList', headers: { 'Content-Type': 'application/json; charset=utf-8', 'dataType': 'json' }, data: { mylist : $scope.mylist } } $http(httpreq).success(function (response) { callmsg(" invoice Saved successfully."); }); – Prakasam Jan 18 '19 at 19:28
  • Take a look at [this answer](https://stackoverflow.com/a/20276775/548997). I believe this has to do with the way the data is serialized when sending it to the server. – Lex Jan 18 '19 at 19:38

0 Answers0