title: Call service from controller in AngularJS
body: <p>I am very new to AnjularJs so bear with me. In my current code various controller are using same methods. Methods have been pasted on each controller which is not good practice. But now I want to share those methods between various controller as a CommonUtility.js In order to do that I need to make service or factory that much I got looking online. But not sure how?
  See below code if you can tell me what to do here.
  filename: Controller.js</p>
  
  <pre><code>(function(){ 
    var somecontrollers = angular.module('angular'); 
    somecontrollers.controller('NameofController', function ($scope, $http) {
      //code
      ..
      ..
      ..
    });
  })();
  </code></pre>
  
  <p>Filename: CommonUtilities.js</p>
  
  <pre><code>var CommonUtilities = angular.module('CommonUtilities', [])
    .service('Collapse', function () {
      this.CollapseTree = function () {
        var name 
        return name
      }
      method2
      method3
      ...
    });
  </code></pre>
  
  <p>How do I add reference to commonUtilities.js or its methods in Controller.js? Any help is appreciated.
  Also one more question. How do I use $scope in CollapseTree function?
  Thanks.  </p>