2017-10-06 52 views
-3

我想通过网络API插入在angularJS控制器多行值我怎样才能在表单域发送多行值与angularJS到网页API

<tr ng-repeat="rt in xxtt"> 

     <td> 
    <input type="text" class="form-control" ng-model="rt .name" required /> 
    </td> 
    <td>`enter code here` 
    <input type="text" class="form-control" ng-model="rt .email" required /> 
    </td> 
    </tr> 
    <button class="btn" ng-click="btnSave()"> 
    Save 
    </button> 

$scope.newarray=[]; 
params = { 
      "id": $scope.id 

      "nameList": [ 
        { 
         "name": $scope.name 

        } 
      ] 
     }  
angular.forEach($scope.nameList, function (response) { 
        $scope.newarray.push({ name: response.name }); 
       }); 
params = JSON.stringify(params);   
     alert(params); 
     LoadSvc.LoadData(params).then(function (response) { 
} 

我可以一次 如何添加多个行值我可以在angularjs发送数组值的列表,网页API

+0

没有得到你的问题。你想从web api获取响应并将其设置到UI或从UI发送数据到web api。 –

回答

0

首先你的HTML是无效的,这就是为什么你的NG-重复可能无法工作。您必须在<table></table>中包装<tr></tr>。而且,为了通过web API将数据发送到服务器,您应该使用$http服务。更具体地说,如果你需要“创建”东西你可能会使用POST方法。

欲了解更多信息,你必须看看$http service documentation

结束你的btnSave()应该使这种操作和使用$http服务。

你的finaly代码可能看起来像这样。

模板

<div ng-app="app" ng-controller="AppController"> 
    <table> 
    <tr ng-repeat="rt in xxtt"> 
     <td> 
     <input type="text" class="form-control" ng-model="rt.name" required /> 
     </td> 
     <td>`enter code here` 
     <input type="text" class="form-control" ng-model="rt.email" required /> 
     </td> 
    </tr> 
    </table> 
    <button class="btn" ng-click="btnSave()"> 
    Save 
    </button> 
</div> 

控制器

$scope.btnSave = function() { 

      /** You have to use your endpoint here **/ 
     $http.post('some-endpoint.com', $scope.xxtt).then(function(response) { 
        alert("I've posted data successfully"); 
      },function() { 
      alert("I've failed to post data"); 
     }); 

    } 

这里有一个working sample of your code.

+0

我要插入多行这样PARAMS = { “名”:$ scope.name },但我有孩子PARAMS这样PARAMS {“电子邮件”:$ scope.email}如何发送父母和孩子响应值API通过angularjs – White

+0

$ scope.newarray = []; PARAMS = { “ID”:$ scope.id “名称列表”:[{ “名称”:$ scope.name } ] } angular.forEach($ scope.nameList,函数(响应){ $ scope.newarray.push({name:response.name}); });我需要在webapi中插入nameList数组,如何解决这个问题 – White

+0

使用http POST方法。检查我的回答链接 – Korte