如何获取 ng-repeat 输入 angularjs 的值
how to get the value of ng-repeat input angularjs?
我从ng-repeat创建了一些动态输入。
我只想知道,如何在HTML中获取每个动态生成的输入字段的输入值。https://jsfiddle.net/a6at8js6/5/
.html
<div ng-app="mainApp" ng-controller="mainCtrl">
<div ng-repeat="author in author_group" class="authorAndTagGroup">
<div ng-repeat="(key, value) in author">
<label class="col-sm-3 control-label">{{key}}</label>
<input type="text" value="{{value}}">
</div>
</div>
</div>
Angularjs
var app = angular.module("mainApp", []);
app.controller('mainCtrl', function($scope){
$scope.authors = [{'author_name': 'akshay', 'about_author':'this is about author', 'author_image':'image url here'}];
$scope.author_group = [];
for (var key in $scope.authors) {
$scope.author_group.push({'Author Name' : $scope.authors[key].author_name, 'About the Author' : $scope.authors[key].about_author, 'Author Image' : $scope.authors[key].author_image, 'Author Linkedin Profile' : '', 'Author Twitter Profile' : ''});
}
console.log($scope.author_group);
});
将输入文本绑定到作者对象的 key'd 属性工作。
<input type="text" ng-model="author[key]">
请注意,ebinmanuval 建议的以下内容不起作用;这是因为它无法改变底层作者对象,而只是覆盖 value 属性。这里的诀窍是,我们希望将模型绑定到像对象这样的引用类型,而不是像字符串这样的值类型,这样当我们改变模型时,底层类型也会发生变化:
<input type="text" ng-model="value">
https://jsfiddle.net/775dfa9y/4/
相关文章:
- 如何使用ng repeat中的选定输入更新我的对象
- 如何验证使用 ng-repeat、ng-show(角度)动态创建的输入
- 如何获取 ng-repeat 输入 angularjs 的值
- 输入文本框 ng-repeat内的验证
- 根据条件使用ng repeat动态显示输入复选框
- 在角度材料对话框数据输入/推送后更新ng-repeat
- 嵌套的 ng-repeat 在<输入>中不起作用
- ng-repeat中的角度文件输入(引导)不起作用
- ng-repeat中的输入总和
- AngularJS-将模型绑定到未使用ng repeat创建的输入
- 从ng repeat内部的输入多次调用ng更改函数
- AngularJS的ng-repeat创建输入
- 在ng-repeat指令中预填充输入文本
- Ng-disabled不允许在ng-repeat的输入文本框中输入多个文本
- 将所有值保存在ng-repeat格式的输入框中
- 带多个无线电输入的AngularJS ng-repeat
- 过滤ng-repeat基于搜索输入与转换过滤器
- 如何从Angular中的ng repeat中获取输入值
- 角ng-repeat输入过滤器加倍搜索中的第一个字符
- Angular将ng-repeat输入值存储到模型中