title: Display checkboxes in with AngularJS based on two object arrays
body: <p>I know there are several similar topics already but I found none that really matches my problem.</p>
  
  <p>When opening my AngularJS app/website I am loading two arrays of objects (both are of the same type). One list contains all possible values (called sources here) and the other list is a selection of elements from the first.</p>
  
  <p>My goal is display all sources as checkboxes. The ones from the second list have to be preselected, the rest not. Now the user can select/deselect checkboxes. If he does so I need to inform the server (with the source.id).</p>
  
  <p>What I got so far:</p>
  
  <pre><code>exampleApp.controller('testController', [ '$scope', '$http', function($scope, $http) {
          $scope.sources = [];
          $scope.selectedSources = [];
          $scope.changeSource = function(source) {...};
      })
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;div ng-repeat="source in sources"&gt;
              &lt;input
                      type="checkbox"
                      name="source.name"
                      value="{{source.id}}"
                      ng-model="??"
                      ng-change="changeSource(source.id)"
              &gt; {{source.name}}
          &lt;/div&gt;
  </code></pre>
  
  <p>What I can't figure out is how I can get ng-model to preselect the right checkboxes and how to get the new (and old) values to changeSource(). Is there an elegant way of doing that?</p>
  
  <p>Example (Pseudo code only):</p>
  
  <pre><code>Sources = [{id=1, name=test1},{id=2, name=test2}, ...]
  SelectedSources = [{id=2, name=test2}]
  </code></pre>
  
  <p>Now what I need are checkboxes like this:</p>
  
  <pre><code>[ ] test1 [x] test2
  </code></pre>
  
  <p>where all elements from sources are checkboxes and the ones from selectedsources are preselected. Changes of the selection can be stored in selected sources (as objects) and have to trigger my changeSource() function so that I can inform my server.</p>