title: AngularJS - Find all ngModel in the current scope
body: <p>I have a HTML template like this:</p>
  
  <pre><code>&lt;div ng-controller="MyCtrl"&gt;
      &lt;input ng-model="model.name" /&gt; {{model.addr}}
      &lt;button ng-click="detect()"&gt;detect&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And this is the controller:</p>
  
  <pre><code>function MyCtrl($scope) {
      $scope.detect = function() {
          var fields = []; //['model.name', 'model.addr']
          //call server with selected fields
      }
  }
  </code></pre>
  
  <p>The template can be customized by user and generated dynamically, not static template. I want to optimize the data model returned from server, only return values for needed fields in the template. The idea is I want to get all the ng-model fields from template and pass them to the server. The returned data will contain only values for these fields, instead of whole data model, for example:</p>
  
  <pre><code>{
      name: 'Superhero',
      addr: 'Mars'
  }
  </code></pre>
  
  <p>If I change the template like this (remove model.addr):</p>
  
  <pre><code>&lt;div ng-controller="MyCtrl"&gt;
      &lt;input ng-model="model.name" /&gt;
      &lt;button ng-click="detect()"&gt;detect&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The fields array should be <code>['model.name']</code> and the returned data from the server should be:</p>
  
  <pre><code>{
      name: 'Superhero'
  }
  </code></pre>
  
  <p>There are any ways to get all ng-model fields in the scope?
  Thanks!</p>