AngularJs error Cannot read property 'then' of undefined
<p>This is module</p>

<pre><code>(function(){

    /**
    * app Module
    *
    * Description
    */
    angular.module('app',[]);
})();
</code></pre>

<p>I have this service </p>

<pre><code>(function(){
    'use strict';

angular
    .module('app')
    .factory('homeservice',homeservice);

homeservice.$inject = ['$http']

function homeservice($http){

    var service = {
        test : test
    }
    return service;

    /**
     * get articles
     * @return {[type]} [description]
     */
    function test(){
      $http.get('/test')
         .then(testSuccess)
         .catch(testError)

      function testSuccess(response){
         return response.data;
         //console.log(response.data) this line prints data to console
      }

      function testError(error){
         return error;
      }
    }
}
})();
</code></pre>

<p>This is my controller which calls function </p>

<pre><code>(function(){


angular.module('app')
       .controller('HomeController',HomeController);

    HomeController.$inject = ['homeservice']
    function HomeController(homeservice) {
        var vm = this;

        test();

        function test(){
             homeservice.test().then(function(response){
                console.log(response);
            });
        }

    }
    })();
</code></pre>

<p>I keep getting the error - <strong><em>Cannot read property 'then' of undefined</em></strong> when I call a method in my controller. I have used this way before and It works properly.</p>

<p><strong>ANSWER</strong></p>

<pre><code>function test(){
          return $http.get('/test') // return was missing here
             .then(testSuccess)
             .catch(testError)

          function testSuccess(response){
             return response.data;
             //console.log(response.data) this line prints data to console
          }

          function testError(error){
             return error;
          }
        }
</code></pre>

<p>I was missing <strong>return</strong> at <strong>$http.get('/test')</strong></p>