title: AngularJS 'this' reference in $timeout function not working
body: <p>I have an AngularJS question that is driving me absolutely crazy. I have a service that looks like this (this is an example to illustrate the issue)</p>
  
  <pre><code>var app = angular.module('test-module');
  
  app.service('ToolService', function($timeout){
  
      this.doSomething = function() {
         console.log("y u no referenced as method?!?");
      }
  
      this.runTimeoutExample = function(){
          $timeout(function(){
              this.doSomething();
          }, 1000);
      }
  })
  </code></pre>
  
  <p>My controller looks like this:</p>
  
  <pre><code>var app = angular.module('test-module', []);
  
  var ctrl = app.controller('main-controller', function($scope, ToolService) {
  
      $scope.somethingWasClicked = function() {
          ToolService.runTimeoutExample();
      }
  
  });
  </code></pre>
  
  <p>Here's the issue, when the button that was clicked that calls $scope.somethingWasClicked it forwards the call to the service and I get an error saying "this.doSomething is not a function".</p>
  
  <p>Why? And how do I fix this? I'm having a hard time finding a way around needing my code to run like this without adding unnecessary logic into my controller.</p>
  
  <p>Thanks in advance for your help </p>