【问题标题】:AngularJS - inputs in a html-table inside a formAngularJS - 在表单内的 html 表中输入
【发布时间】:2017-02-17 19:52:52
【问题描述】:

现在可以了……

我在输入中获取数组并粘贴名称,然后在输入中更改名称并将其放入。

HTML

<form id="edit">
    <table>
        <tr>
            <th>Name: </th>
            <td>
                <input id="name" form="edit" type="text" ng-model="name" required>
            </td>
        </tr>
    </table>
    <button ng-click="edit()">Submit</button>
</form>

AngularJS

$scope.display = function()
{
    var connection = $http(
    {
        method: 'GET',
        url: 'http://localhost:8080/students?id=' + $scope.id
    })

    .then(function(response)
    {
        $scope.myArray = response.data;
        $scope.name = $scope.myArray[0].name;
    })

【问题讨论】:

  • 使用angular时不需要type submit!
  • “提交失败”实际上是什么意思?您在这里使用的是ng-click,它与input 没有任何关系。

标签: angularjs forms html-table


【解决方案1】:

您需要检查response 上的 status_code 而不是 response.data:

    if (response.status == 200) 
    {
        success();
    } 
    else 
    {
        fail();
    }

【讨论】:

  • 看上面的代码示例。不要从 $scope.myResponse 分配中删除 .data,仅用于 if/then 检查。
  • 我看到分配没有取得任何成果,但它仍然喜欢 response.data 而不是 response.status - 我已经更新了帖子中的代码
【解决方案2】:

点击按钮时,您应该检查控制器中的$scope.name 是否正确更新。您的请求可能会失败,因为您的 $scope.name 没有在控制器中正确更新。

【讨论】:

  • 您的双向绑定无法正常工作。请初始化$scope.name = undefined。在controller function 之后检查并告诉我。
  • 还是没有运气,我在桌子内外测试,桌子外面工作正常,桌子里面没有运气
  • 然后你只需在你的ng-click="edit(name)" 中传递name 并在控制器中更新你的函数,就像$scope.edit = function(name)..url: 'http://localhost:8080/students?name=' + name 一样适合你。
  • @user3121518 你可以在这里查看你的问题答案“stackoverflow.com/questions/12618342/…”这里是讨论为什么不使用 $scope.var ...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 2014-04-30
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 2016-05-17
相关资源
最近更新 更多