title: ng-options select list value set to the id of my choice and binding it correctly with ng-model
body: <p>With angular I would like to make a select list with value that takes the id of my choice (actual id property of an object) and I would like to bind it correctly with ng-model directive.</p>
  
  <p>Here is what I've tried : </p>
  
  <pre><code>&lt;select ng-model="selectedPersonId"                 
  ng-options="p.id as p.name for p in People track by p.id"&gt;&lt;/select&gt;
  
  $scope.People = [
      { name : "Fred", id : 1 },
      { name : "Joe", id : 2 },
      { name : "Sandra", id : 3 },
      { name : "Kacey", id : 4 },
      { name : "Bart", id : 5 }
  ];
  
  $scope.setTo1 = function(){
      $scope.selectedPersonId = 1;
  }
  </code></pre>
  
  <p><a href="http://jsfiddle.net/b7dyadnr/" rel="noreferrer">http://jsfiddle.net/b7dyadnr/</a></p>
  
  <p>Here select option value is the correct value (value is the id of person in people) and text is correct. But the binding doesn't work so if I set the value of $scope.selectedPersonId the selection is not reflected on the list. </p>
  
  <p>I know I can make it work like this : </p>
  
  <pre><code>&lt;select ng-model="selectedPersonId"                 
  ng-options="p.id as p.name for p in People"&gt;&lt;/select&gt;
  </code></pre>
  
  <p><a href="http://jsfiddle.net/rgtbn2f5/" rel="noreferrer">http://jsfiddle.net/rgtbn2f5/</a></p>
  
  <p>There it works I can set $scope.selectedPersonId and the changes are reflected on the list. But then the id used in the select list option value is not the id of the actual person ! </p>
  
  <pre><code>&lt;option value="0"&gt;Fred&lt;/option&gt; &lt;!--option value is 0 which is not the true id of fred --&gt;
  &lt;option value="1" selected="selected"&gt;Joe&lt;/option&gt;
  ...
  </code></pre>
  
  <p>I want to use it like this except that I want angular to use the true id of the person in the select option value and not the index of the array or whatever thing it uses. </p>
  
  <p>If you wonder why I want to use it like this it is because the id is sent to an API and the model can also be set using querystring so I must make it work like this.  </p>