首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将动态输入数据添加到$http数据中

如何将动态输入数据添加到$http数据中
EN

Stack Overflow用户
提问于 2017-08-28 19:14:40
回答 1查看 62关注 0票数 1

我有一个具有动态生成输入框的表单,现在如何将动态表单数据添加到angularjs中的$http数据中?

控制器代码:

代码语言:javascript
运行
复制
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");
                    });
                }
            });
EN

回答 1

Stack Overflow用户

发布于 2017-08-28 19:24:58

在视图中使用ng模型将输入绑定到控制器中的数据,然后在单击按钮时调用http post。

认为:

代码语言:javascript
运行
复制
<input type="text" ng-model="toBind"></div>

在模型中:

代码语言:javascript
运行
复制
 $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");
                });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45925914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档