首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将动态生成的输入绑定到$scope

如何将动态生成的输入绑定到$scope
EN

Stack Overflow用户
提问于 2017-05-03 15:16:34
回答 1查看 52关注 0票数 1

我正在从db检索项目--把它们放在dir-分页或ng--重复我在这里输入的id作为模型名来获得键和名称,就像我获取数组来创建许多输入并在控制器中检索它们一样,但是当我用console.log($scope.values)检索ng模型对象值时,它说没有定义。如何将多个生成的输入传递给作用域对象中的控制器是我的问题,即使是ng-单击“不工作”??视图

代码语言:javascript
复制
<form angular-validator-submit="submitForm()"
    name="submit-form" class="form-horizontal" novalidate
    angular-validator>
    <table>
    <thead>
    <tr>
    <th>S.No</th>
    <th>id</th>
    <th>Name</th>
    </tr>
    </thead>
    <tbody>
    <tr dir-paginate="x in items| itemsPerPage: pageSize" current-page="currentPage">
        <td><input type="text" name="id" ng-model="values.{{x.id}}[$index]"></td>
        <td><input type="text" name="test" ng-model="values.{{x.name}}[$index]"></td>
        </tr>
        </tbody>
        </table>
        <button type="submit" class="btn btn-primary">Save</button>
    </form>

        $scope.submitform = function(){
        console.log($scope.values);
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-04 09:22:19

ng-model="values[x.id]"将按照注释中的建议进行工作并定义$scope.values = [];

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43764028

复制
相关文章

相似问题

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