title: Including External Factories in AngularJs Modules
body: <p>I would like to create a factory to abstract my <code>$http</code> calls.  I would like to use this factory in multiple modules, but I only wish to maintain one copy of the file.</p>
  
  <p>I see that I am doing something similar with <code>kendo.directives</code>:</p>
  
  <pre><code>angular.module('createPolicy', ['kendo.directives'])
      .controller('CreatePolicyController', ['$scope', function ($scope) {
  </code></pre>
  
  <p>How can I create my factory such that I can simply include it like <code>kendo.directives</code> after I include the <code>.js</code> source?</p>
  
  <p>For example:</p>
  
  <pre><code>angular.module('createPolicy', ['kendo.directives', 'myPolicyService'])
      .controller('CreatePolicyController', ['$scope', function ($scope) {
  </code></pre>
  
  <p>How would I have to construct the factory to be able to use it like that?</p>
  
  <p><strong>Edit:</strong> I have the following in angular-factories.js:</p>
  
  <pre><code>var policyService = angular.module("PolicyService", []);
  policyService.factory('PolicyService', function ($http) {
      return {
          getFoos: function () {
              //return the promise directly.
              return $http.get('/foos')
                        .then(function (result) {
                            //resolve the promise as the data
                            return result.data;
                        });
          }
      }
  });
  </code></pre>
  
  <p>Then, in a different file, I try to use it like so:</p>
  
  <pre><code>angular.module('createPolicy', ['kendo.directives', 'PolicyService'])
      .controller('CreatePolicyController', ['$scope', function ($scope, policyService) {
          $scope.editPolicy = true;
          $scope.packages = [];
  
          console.log(policyService.getFoos());
  </code></pre>
  
  <p>But, I get the error:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'getFoos' of undefined</p>
  </blockquote>
  
  <p>I am including the files like this (in ASP.NET MVC):</p>
  
  <pre><code>bundles.Add(new ScriptBundle("~/bundles/jqueryplugins").Include(
      "~/Scripts/angular.min.js",
      "~/Scripts/angular-factories.js",
      "~/Scripts/kendo.all.min.js",
      "~/Scripts/kendo.aspnetmvc.min.js"));
  </code></pre>