title: Refresh resource query on click in angular factory?
body: <p>i am starting to learn angularJS and i am stuck figuring out how to pass  a variable to a factory and refresh the resource on a click event.</p>
  
  <p>Specifically i don't know how to pass the search variable from the form field to the factory, passing it instead of the hardcoded '???' into params: {query:'???'} ... Then, on submit the resource should be fetched again with that search parameter... i tried to use "searchterms" variable in there but it outputs "searchterm" undefined in the console.</p>
  
  <pre><code>    &lt;html ng-app="notmuchApp"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;notmuch sinatra&lt;/title&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"&gt;
      &lt;script src="js/angular.js"&gt;&lt;/script&gt;
    &lt;script src="js/angular-resource.js"&gt;&lt;/script&gt;
    &lt;script src="js/ui-bootstrap-tpls-1.1.2.js"&gt;&lt;/script&gt;
      &lt;script&gt;
  
    var notmuchApp = angular.module('notmuchApp', ['ui.bootstrap','ngResource']);
    notmuchApp.controller('handleSearch', ['$scope', 'getSearch',
      function ($scope, getSearch) {
          $scope.searchresults = getSearch.query();
      }]);
  
    notmuchApp.factory('getSearch', function ($resource) {
      return $resource('/notmuch/search', {}, {
          query: { method: 'GET', params: {query:'???'}, isArray: true },
      })
  });
  
    &lt;/script&gt;
    &lt;/head&gt;
   &lt;body &gt;
    &lt;div ng-controller="handleSearch"&gt;
    &lt;form ng-submit="getSearch"&gt;
      &lt;input type="text" ng-model="searchterm"&gt; 
      &lt;input type="submit" value="Search"&gt;
    &lt;/form&gt;
      Results:
      &lt;ul&gt;
        &lt;li ng-repeat="searchresult in searchresults"&gt;
           {{searchresult.date_relative}} {{searchresult.authors}} {{searchresult.subject}}
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>