Get all data from form by ng-click AngularJs

Issue

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<div ng-app="myApp">
   <div class="container" ng-controller="CtrlList">
      <div class="row">          
          <div ng-repeat="x in users track by $index">
              <div><input type=text  ng-model="x.id"></div>
              <div><input type=text  ng-model="x.title"></div>
              <div><input type=text ng-model="x.completed"></div>                 
          </div>
          <button ng-click="submit(x)">save </button>
      </div>

In Controller

$scope.submit = function(data){
   console.log(data)  // undefined
}

So when i click on submit button data is undefined.. how can i get the form data here ? Any help is appreciated

Solution

To get the data here We have to pass origin model.. for ex

      <div ng-repeat="x in users track by $index">
          <div><input type=text  ng-model="x.id"></div>
          <div><input type=text  ng-model="x.title"></div>
          <div><input type=text ng-model="x.completed"></div>                 
      </div>
          <button ng-click="submit(users)">save </button>

Answered By – jsduniya

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.