Angularjs ng-model input does not work [text])

I have data from the database in a loop, and it works fine, and the value is in the input field, but when I want to read this value after clicking angular, return me:

Object {newName: undefined, newEmail: undefined}

and I do not know why. Please ask for help.

HTML CODE:

<tr ng-repeat="user in users">
    <td><input type="text" ng-model="user.name" name="user.name" ></td>
    <td><input type="text" ng-model="user.email" name="user.email" ></td>
    <td><button ng-click="checkData()">Click</button></td>
</tr>

CONTROLLER CODE:

 $scope.user = {};
 $scope.checkData = function () {
   var data = {
      newName: $scope.user.name,
      newEmail: $scope.user.email
   };
 console.log(data);
+4
source share
3 answers

ng-repeat users, tr table. , , user checkData, .

<tr ng-repeat="user in users">
    <td><input type="text" ng-model="user.name" name="user.name" ></td>
    <td><input type="text" ng-model="user.email" name="user.email" ></td>
    <td><button ng-click="checkData(user)">Click</button></td>
</tr>

$scope.checkData = function (user) {
   var data = {
      newName: user.name,
      newEmail: user.email
   }
   console.log(data);
};
+2

ng-click user , ng-click="checkData(user)"

:

$scope.user = {};
$scope.checkData = function (user) {
  console.log(user);
};
+1

DOM, , :

<tr ng-repeat="user in users">
  <td>{{user.name}}</td>
  <td>{{user.email}}</td>
  <td><button ng-click="check(user)"></button></td>
</tr>



$scope.check = function (thing) {
  var currentUser = {
    name: thing.name,
    email: thing.email
  }
}
0

Source: https://habr.com/ru/post/1612604/


All Articles