title: How to include/inject functions which use $scope into a controller in angularjs?
body: <p>I am trying to include a library of functions, held in a factory, into a controller.
  Similar to questions like this:
  <a href="https://stackoverflow.com/questions/11324202/angularjs-common-controller-functions">Creating common controller functions</a></p>
  
  <p>My <strong>main controller</strong> looks like this:</p>
  
  <pre><code>recipeApp.controller('recipeController', function ($scope, groceryInterface, ...){
  
  $scope.groceryList = [];
  // ...etc...    
  
  /* trying to retrieve the functions here */
  $scope.groceryFunc = groceryInterface; // would call ng-click="groceryFunc.addToList()" in main view
      /* Also tried this:
      $scope.addToList = groceryInterface.addToList();
      $scope.clearList = groceryInterface.clearList();
      $scope.add = groceryInterface.add();
      $scope.addUp = groceryInterface.addUp(); */
  }
  </code></pre>
  
  <p>Then, in another .js file, I have created the factory groceryInterface. I've injected this factory into the controller above.</p>
  
  <p><strong>Factory</strong></p>
  
  <pre><code>recipeApp.factory('groceryInterface', function(){
  
          var factory = {};
  
      factory.addToList = function(recipe){
          $scope.groceryList.push(recipe);
                      ... etc....
      }
  
      factory.clearList = function() {
              var last = $scope.prevIngredients.pop();
              .... etc...
      }
  
      factory.add = function() {
      $scope.ingredientsList[0].amount = $scope.ingredientsList[0].amount + 5;
      }
  
      factory.addUp = function(){
          etc...
      }
  
      return factory;
  });
  </code></pre>
  
  <p><strong>But in my console I keep getting <code>ReferenceError: $scope is not defined
      at Object.factory.addToList</code>, etc.</strong> Obviously I'm guessing this has to do with the fact that I'm using <code>$scope</code> in my functions within the factory. How do I resolve this? I notice that in many other examples I've looked at, nobody ever uses <code>$scope</code> within their external factory functions. I've tried injecting <code>$scope</code> as a parameter in my factory, but that plain out did not work. (e.g. <code>recipeApp.factory('groceryInterface', function(){</code> ) </p>
  
  <p>Any help is truly appreciated!</p>