I have a controller calling a service, which performs a number of http calls and returns back a set of data to my controller. The problem i am facing is that my service returns some data (typically emtpy) before all the http calls have been completed, and as a result, $scope.myForksLinks is undefined.
Controller:
myService.getMyData()
    .then(function(response) {
        $scope.myUrl = response.myForksLinks;
    });
MyService:
handleResolveReject() {
    return promise.then(function(v) {
        return {v:v, status: "resolved"};
    }, function(e) {
        return {e:e, status: "rejected"};
    });
},
getMyData() {
    const that = this;
    var deferred = that._$q.defer();
    var httpResponse = [];
    var httpLinks = [
        {myTablesLinks: this.tablesLinks}, // this.tablesLinks = [http://tablelink1.come, http://anotherTableLink.com]
        {myGlassesLinks: this.glassesLinks},
        {myPlatesLinks: this.platesLinks},
        {myCupsLinks: this.cupsLinks},
        {myForksLinks: this.forksLinks},
    ]
    var getData = function() {
        _.forEach(httpLinks, function(httpSet, k) {
            _.forEach(httpSet, function(links, httpName) {
                var promises = [];
                angular.forEach(links, function(link) {
                    var promise = that._$http({
                        method: 'GET',
                        url: link + '/my/end/point',
                        responseType: 'json'
                    });
                    promises.push(promise)
                });
                return Promise.all(promises.map(that.handleResolveReject))
                    .then(function(results)) {
                        httpResponse.push({httpName: results.filter(x => x.status === 'resolved')});
                    });
            });
        });
        return httpResponse;
    };
    deferred.resolve(getData());
    return deferred.promise;
}
 
    