AngularJS and Promise
<p>I have a project build in AngularJS and I make a http get request to an api that respond with an array.</p>

<p>The problem is that in the response I have a promise and not the array I need.<br>
If I try to assign it to a scope it is undefined.</p>

<p>This is the factory code:</p>

<pre><code>angular.module('app')

.factory('utils', function($rootScope, $translate, $state, $sce, $http) {
    return {
        settings: {},
        getLanguages: function(){

            var _url = $rootScope.baseUrl+'/languages';
            var lang = $http({
                withCredentials: false,
                url: _url,
                method: "GET",
                headers: { 'Content-Type': undefined },
                transformRequest: angular.identity
            });

            return lang;
        }
    };
});
</code></pre>

<p>This is the directive code:</p>

<pre><code>angular.module('app').directive('leftPanel', function($rootScope, player, search, users, utils) {
    return {
        restrict: 'E',
        templateUrl: 'assets/views/directives/left-panel.html',
        replace: true,
        scope: true,
        link: function($scope, el) {
            var searchBar = el.find('input');

            $scope.player = player;
            $scope.search = search;
            $scope.users  = users;

            utils.getLanguages().then(
                function(answer){
                    $scope.languages = answer.data;
                }
            );

            console.log($scope.languages);

            searchBar.on('focus', function() {
                if (search.query || search.results.length) {
                    search.showPanel();
                }
            });

            if ($rootScope.isPhone) {
                $rootScope.$on('$stateChangeStart', function() {
                    el.addClass('closed');
                });
            }
        }
    };
});
</code></pre>

<p>The problem is in</p>

<pre><code>utils.getLanguages().then(
                function(answer){
                    $scope.languages = answer.data;
                }
            );

            console.log($scope.languages);
</code></pre>

<p>I get <code>undefined</code></p>