title: Angular $injector - Unknown Provider for Angular's $timeout
body: <p>I'm trying to inject angular's <code>$timeout</code> service in a method that should be called in several controllers in my application. However, I'm always getting the error:</p>
  
  <blockquote>
    <p>Error: [$injector:unpr] Unknown provider: $timeoutProvider &lt;- >$timeout</p>
  </blockquote>
  
  <p>Of course <code>$timeout</code> has to be known since it's an angular service, so I don't see why this error is happening.</p>
  
  <p>This is my code:</p>
  
  <pre><code>HTML:
  &lt;div ng-app="app" ng-controller="sampleController"&gt;
      &lt;button ng-click="doit()"&gt;Do It!&lt;/button&gt;
  &lt;/div&gt;
  
  JAVASCRIPT:
  var app = angular.module('app', []);
  app.controller('sampleController', ['$scope', function($scope) {
      var _this = this;
  
      $scope.doit = function() {
          var $injector = angular.injector();
          var $timeout = $injector.get('$timeout', _this);
  
          $timeout(function () { alert('ok'); });
      };
  }]);
  </code></pre>
  
  <p>And here's a jsfiddle demonstrating the problem:</p>
  
  <p><a href="https://jsfiddle.net/fvw8zss5/" rel="nofollow">https://jsfiddle.net/fvw8zss5/</a></p>
  
  <hr>
  
  <ul>
  <li>This is not a question about if that's a bad practice or not. Of course it is bad. It's a question about why it was not working.</li>
  <li>The JsFiddle will work if you know how to use JsFiddle.</li>
  </ul>