title: How to add object properties from ng-checked items to my ng-model object
body: <p>I have four input fields which I'm using to add properties to a single object using ng-model= model.propertyName. I have a series of check boxes that I'm creating with ng-repeat that I could not figure out how to add unique propertyNames for each ng-model as they were created with the ng-repeat. As a work-around(or maybe this is correct, I'm not sure) I was able to write a function to add the checked items to an array. I was then trying to use a for-loop to iterate over the array and add each selected propertyName(string) to the ng-model object as a new property using a ng-click to call the function.</p>
  
  <p>As-is when I click the "Add Technician" button I get the following error output:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'selection' of undefined
        at Scope.$scope.addTechnician (..../scripts/controllers.js:</p>
  </blockquote>
  
  <p>This occurs because $scope is undefined inside the conditional of my for loop in the addTechnician function. I can't understand why because when I pass $scope to the addTechnician function it recognizes the newTech inside the for loop. When I don't pass $scope to the addTechnician function it says newTech is undefined with the following error:</p>
  
  <blockquote>
    <p>TypeError: Cannot set property 'cert1' of undefined<br>
    at Scope.$scope.addTechnician(.../scripts/controllers)</p>
  </blockquote>
  
  <p>I'm pretty sure this has something to do with the way ng-repeat creates a new scope, which prototypically inherits from the parent scope. But again, I'm not sure.</p>
  
  <p>Here is my controller</p>
  
  <pre><code>use strict';
  angular.module('Carrepair2.controllers', [])
  
  .controller('SetupCtrl', function($scope) {
  
    $scope.certifications = [
      {'name':'Engine Repair'},
      {'name':'A/T &amp; Transaxle'},
      {'name':'Manual Drive Train &amp; Axles'},
      {'name':'Suspension &amp; Steering'},
      {'name':'Brakes'},
      {'name':'Electrical &amp; Electronic Systems'},
      {'name':'Heating &amp; Air Conditioning'},
      {'name':'Engine Performance'},
      {'name':'Light Vehicle Diesel Engines'}
    ];
  
    // selected certifications
    $scope.selection = [];
  
    $scope.toggleCert = function(name) {
      var idx = $scope.selection.indexOf(name);
  
      //is currently selected
      if (idx &gt; -1) {
        $scope.selection.splice(idx, 1);
      }
      //is newly selected
      else{
        $scope.selection.push(name);
      }
    };
  
    $scope.addTechnician = function($scope) {
      for(var i=0; i &lt; $scope.selection.length - 1; i++){
        $scope.newTech['cert' + (i + 1).toString()] = $scope.selection[i].name;
      }
    };
  
  })
  </code></pre>
  
  <p>Here is my template</p>
  
  <pre><code>&lt;form class="col-md-6"&gt;
      &lt;div class="input_wrapper"&gt;
          &lt;input type="text" name="first-name" ng-model="newTech.firstName" required&gt;
          &lt;label for="first-name"&gt;First Name&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="input_wrapper"&gt;
          &lt;input type="text" name="last-name" ng-model="newTech.lastName" required&gt;
          &lt;label for="last-name"&gt;Last Name&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="input_wrapper"&gt;
          &lt;input type="email" name="email" ng-model="newTech.email" required&gt;
          &lt;label for="email"&gt;Email&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="input_wrapper"&gt;
          &lt;input type="tel" name="phone" ng-model="newTech.phone" required&gt;
          &lt;label for="phone"&gt;Phone&lt;/label&gt;
      &lt;/div&gt;
      &lt;h5&gt;Check all held ASE certifications&lt;/h5&gt;
      &lt;ul class="list"&gt;
          &lt;li class="item item-checkbox" ng-repeat="certification in certifications"&gt;
          &lt;label class="checkbox"&gt;
              &lt;input type="checkbox" value="{{certification.name}}" ng-checked="selection.indexOf(certification.name) &gt; -1" ng-click="toggleCert(certification)"&gt;
          &lt;/label&gt;
          {{certification.name}}
      &lt;/li&gt;
      &lt;/ul&gt;
      &lt;button class="button button-block" ng-click="addTechnician()"&gt;Add Technician&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Ideally after the "Add Technician" button is clicked I want to end up with an object, my newTech ng-model object, that has the input field data and the properties from the checked items. Here is a jsFiddle with simplified code replicating the problem</p>
  
  <p><a href="http://jsfiddle.net/aq93z/7/" rel="nofollow">http://jsfiddle.net/aq93z/7/</a></p>