Getting empty return result in $http.get() in AngularJS 1.5.0
<p>I have created a factory in my AngularJS application which is used to bring in refreshed data from server after a delete has been performed on one or more elements of the list. </p>

<pre><code>var myApp = angular.module('app');
myApp.factory('mvListRefresher', function($http) {
    return {
        refreshCourses : function() {
            var list = new Array();
            $http.get('/api/courses').then(function(response) {
                console.log('got refreshed lists');
                console.log(response.data);
                list = response.data;
            }, function(error) {
                console.log('error in retreiving fresh lists');
                console.log(error);
            });

            console.log('Displaying list of courses');
            console.log(list);
            if(list.length != 0) {
                return list;
            }
        }
    }
});
</code></pre>

<p>I'm calling this factory in one of my controllers by calling</p>

<pre><code>$scope.courses = mvListRefresher.refreshCourses();
</code></pre>

<p>But I'm getting an empty list, i.e I'm not getting any return value at all. In my factory function I observed that the line</p>

<pre><code>console.log(list);
</code></pre>

<p>always prints out an empty array, however the line</p>

<pre><code>console.log(response.data);
</code></pre>

<p>which is inside the success callback prints out the full list of objects correctly. I don't know how this is happening. I'm relatively new to AngularJS's promises and it's asynch methods and architecture. Kindly help me out. If you need any more info i'll provide it. I've done the entire app using MEAN. Thanks in advance!</p>