title: AngularJs, troublesome filter function
body: <p>I'm trying to learn AngularJS but got stuck on my filter function.</p>
  
  <p>I have a JSON file containing persons and a service &amp; controller that loads it.</p>
  
  <pre><code>[{
  "id": "000000-0000",
  "name": "John Doe"
   },
   ...
  </code></pre>
  
  <p>So far so good, then in my form which is connected to person.id &amp; person.name I would like to be able to pick the current person using a searchbox. I created a inputfield named searchText and wrote a searchFilter function. I would like to set the $scope.person to match the searchText criteria so that it updates my inputboxes (person.name, person.id with the corresponding values.</p>
  
  <pre><code> .controller('MyCtrl1', ['$scope', 'Persons', function($scope, Persons) {
      $scope.persons = Persons.query();
  
      $scope.searchFilter = function(obj) {
         var p = new RegExp($scope.searchText, 'i');
         $scope.person = ????
              };
  
          }])
  </code></pre>
  
  <p>How could that be done? By applying the same filter to every single input?
  Regards</p>
  
  <p>UPDATE: To clarify, if the searchText matches none or several posts, the form remains empty. If and when it matches a unique post, this post become $scope.person and the form is filled with the persons values</p>