title: Define and get values from angularJS table
body: <p>Here is my angularjs code to get values in a table and save. If I put some data in  table and save, Its working fine but if I click save without entering any data in table it shows error as</p>
  
  <p>TypeError: $scope.item is undefined</p>
  
  <p>Here is my code and please help me. I am a newbie in angularJS</p>
  
  <pre><code>    &lt;div ng-app="Myapp"&gt;
  
      &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"&gt;&lt;/script&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"&gt;&lt;/script&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-messages.js"&gt;&lt;/script&gt;
           &lt;script&gt;
              var Myapp = angular.module('Myapp', ["ngRoute"]);
          &lt;/script&gt;
  
          &lt;div ng-controller="orderFormController"&gt;
              &lt;table  id="item_table"&gt;
                  &lt;thead&gt;
                      &lt;tr class="headings"&gt;
                          &lt;th class="column-title"&gt;Item &lt;/th&gt;            
                          &lt;th class="column-title"&gt;Rate&lt;/th&gt;                          
  
                          &lt;/th&gt;
  
                      &lt;/tr&gt;
                  &lt;/thead&gt;
  
                  &lt;tbody&gt;
                      &lt;tr&gt;
                          &lt;td&gt;         
                              &lt;input type="text" name="item"  ng-model='item[0]'&gt;
                          &lt;/td&gt;
  
                          &lt;td&gt;
                          &lt;input type="text" name="rate"  ng-model='rate[0]'&gt; 
                         &lt;/td&gt;
  
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;         
                              &lt;input type="text" name="item"  ng-model='item[1]'&gt;
                          &lt;/td&gt;
  
                          &lt;td&gt;
                          &lt;input type="text" name="rate"  ng-model='rate[1]'&gt; 
                          &lt;/td&gt;
  
                      &lt;/tr&gt;
  
  
                  &lt;/tbody&gt;
  
              &lt;/table&gt;
              &lt;button type="button"  ng-click='saveorder()' &gt;SAVE ORDER&lt;/button&gt;
          &lt;/div&gt;    
          &lt;script&gt;
              Myapp.controller('orderFormController', ['$scope', '$http', function ($scope, $http) {
                  var data = {};
                  data['item'] = [];
                  $scope.saveorder = function () {
                      var rowCount = 3;
                      for (i = 1; i &lt; rowCount; i++) {
                          data['item'][i] = {'item': $scope.item[i], 'rate': $scope.rate[i]}
  
                      }
                      alert(data);
                  }
  
              }]);
          &lt;/script&gt;       
  </code></pre>