保存所有的值输入文本框是在NG-重复 [英] Save all the values in input text box that is in ng-repeat
本文介绍了保存所有的值输入文本框是在NG-重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找出我怎么能保存输入在输入文本框内 NG-重复
在button.I的一个单一的点击所看到的值像这样的例子<一个href=\"http://stackoverflow.com/questions/11752977/angularjs-ng-model-scope-in-ng-repeat-is-undefined\">getting从文本框中值,让用户可以单独保存每个文本框。
下面是一个示例code:
$ scope.items = [1,2,3,4]&LT; DIV NG重复=项中的项目&GT;
&LT;输入类型=文本NG-模式= item.id&GT;
&LT; / DIV&GT;
&LT;按钮式=按钮NG点击=saveAllValues()&GT;保存&LT; /按钮&GT;
解决方案
您只需绑定 NG-模型
到另一个对象,并使用 $指数
引用索引中非常 NG-重复
:
\r
\r\r
\r VAR对myApp = angular.module('对myApp',[]);\r
\r
myApp.controller('MyCtrl',函数($范围){\r
$ scope.items = [1,2,3,4〕;\r
$ scope.values = [];\r
\r
$ scope.saveAllValues =功能(){\r
警报($ scope.values);\r
}\r
});
\r
&LT;脚本SRC =https://ajax.googleapis.com/ajax /libs/angularjs/1.2.23/angular.min.js\"></script>\r
\r
&LT; DIV NG-应用=对myAppNG控制器=MyCtrl&GT;\r
&LT; DIV NG重复=项中的项目&GT;\r
&LT;输入类型=文本NG-模式=值[$指数]&GT;\r
&LT; / DIV&GT;\r
&LT;按钮式=按钮NG点击=saveAllValues()&GT;保存&LT; /按钮&GT;\r
&LT; / DIV&GT;
\r
I'm figuring out how can I save the values that are entered in the input text box inside ng-repeat
on a single click of a button.I have seen examples like this getting values from text box that lets user to save each text box individually.
Below is a sample code:
$scope.items=[1,2,3,4]
<div ng-repeat="item in items">
<input type="text" ng-model=item.id>
</div>
<button type="button" ng-click="saveAllValues()">Save</button>
解决方案
You just bind the ng-model
to another object and use $index
to refer to the index within the very ng-repeat
:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function($scope) {
$scope.items = [1, 2, 3, 4];
$scope.values = [];
$scope.saveAllValues = function() {
alert($scope.values);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<div ng-repeat="item in items">
<input type="text" ng-model="values[$index]">
</div>
<button type="button" ng-click="saveAllValues()">Save</button>
</div>
这篇关于保存所有的值输入文本框是在NG-重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文