使用ng-repeat创建动态数量的文本框。
<div class="orgevent" ng-repeat="i in getNumber(numOfEvents) track by $index">
<input class="dest" type="text" value="Free text" ng-model="i.freeText">
</div>
&#13;
我想(在点击时)获取用户在textBox中写入的值并将其发送到服务器, 我怎么能这样做?
我试图通过ng-model将它带入JS中,但值总是&#34;未定义&#34;
答案 0 :(得分:1)
您可以将ng-model用作数组并在单击时读取它。看看
http://jsfiddle.net/ucskyv67/74/
app.controller("cookieCtrl", function ($scope, $cookies) {
$scope.numbers= [1,2,3,4,5,6];
$scope.userVals=[];
$scope.getVal= function(){
console.log($scope.userVals);
}
});
<div ng-app="cookieApp" ng-controller="cookieCtrl">
<div class="orgevent" ng-repeat="i in numbers track by $index">
<input class="dest" type="text" value="Free text" ng-model="userVals[$index]">
</div>
<button ng-click="getVal()">Read</button>
</div>
答案 1 :(得分:0)
一个选项是在输入中添加ng-change并在控制器中实现一个方法来调用服务器 -
<input ng-change="handleChange(i.freeText)" class="dest" type="text" value="Free text" ng-model="i.freeText">