title: Collect Array from HTML with angular
body: <p>I'm getting data out of the db with php, to make it available in a form in HTML.
  The li elements look something like this</p>
  
  <pre><code>&lt;input type="checkbox" ng-model="check_list[i]" id="i" value="something"&gt;
  </code></pre>
  
  <p>Of course the "i" is replaced with a number in the actual HTML, so the elements have for example <code>check_list[1]</code>, <code>id=[1]</code> and so on...</p>
  
  <p>How can I now access these ng-models in the controller? I want to iterate over all <strong>existing</strong> <code>check_list[i]</code> elements (it shouldn't be hardcoded which elements exist, I want to leave it generic), and collect them, to send all checked elements back to the php script to store it in the db. So I'm trying something like this.</p>
  
  <pre><code>    submitForm.insertData = function(){
          var check_list_elements = [];
          for(var i = 1; i &lt;= 83; i++) {
              //add only those ng-models check_list[i], that really exist into check_list_elements
              if ($scope.check_list[i] !== undefined){
                  $check_list_elements.push($scope.check_list[i]);
              }
          }
  </code></pre>
  
  <p>But I keep getting </p>
  
  <pre><code>Cannot read property '1' of undefined at t.insertData
  </code></pre>
  
  <p>So <code>$scope.check_list[i]</code> is obviously wrong.</p>
  
  <p>How is it done correctly?</p>