我有一个具有动态生成输入框的表单,现在如何将动态表单数据添加到angularjs中的$http数据中?
控制器代码:
app.controller('saveQues', function ($scope, $http, $location){
$scope.insertData=function(){
$http({
url: "savequestions.php",
method: "POST",
data: #how to add here,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response){
console.log('then');
}).catch(function(response) {
console.error('Gists error', response.status, response.data);
})
.finally(function() {
console.log("finally finished gists");
});
}
});发布于 2017-08-28 19:24:58
在视图中使用ng模型将输入绑定到控制器中的数据,然后在单击按钮时调用http post。
认为:
<input type="text" ng-model="toBind"></div>在模型中:
$scope.insertData=function(){
$http({
url: "savequestions.php",
method: "POST",
data: $scope.toBind,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response){
console.log('then');
}).catch(function(response) {
console.error('Gists error', response.status, response.data);
})
.finally(function() {
console.log("finally finished gists");
});https://stackoverflow.com/questions/45925914
复制相似问题