roro roro - 1 year ago 62
AngularJS Question

ng-model in ng-repeat - how to send values to server

im using ng-repeat to create dynamic number of textboxs.

<div class="orgevent" ng-repeat="i in getNumber(numOfEvents) track by $index">
<input class="dest" type="text" value="Free text" ng-model="i.freeText">

i want (on click) to take the values that the user write in the textBox and send it to the server,
how can i do it?

i tried to take it in the JS by ng-model but the value is always "undefined"

Don Don
Answer Source

You can use ng-model as array and read it on click. Take a look

app.controller("cookieCtrl", function ($scope, $cookies) {
    $scope.numbers= [1,2,3,4,5,6];
  $scope.getVal= function(){

<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]">
    <button ng-click="getVal()">Read</button>