title: AngularJS search - how to cancel previous search
body: <p>I use this code to search items from backend:</p>
  
  <pre><code>$scope.$watch('vm.searchTerm', function(newValue, oldValue) {
      if(oldValue != newValue) {                              
      vm.loadingProducts = true;                  
      myService.findItemsByTerm(searchTerm).then(function(response) {
          vm.myItems = response.data;
          vm.loadingProducts = false;                     
        }, function errorCallback(response) {
          console.log('error search');
        });   
      } 
  });
  </code></pre>
  
  <p>There are a lot of items in backend so the search could take longer.
  And sometimes it can be that an older request is slower than a newer request - the older request than overwrites <strong>vm.myItems</strong>.
  Is there a best practice how to solve this problem - can I cancel an older request somehow with AngularJS?</p>