I have the following service declared:
app.factory('data', ['$http', function ($http) {
        var dataRecords = {};
        //Retrieve the entries from the data file and categorize them according
        //to the information types located in the overview page
        $http.get('data.json')
            .success(function (records) {
                    //Fill the dataRecords variable
        });
        return {
            get: function () {
                return dataRecords;
            },
            setNew: function (newRecords) {
                dataRecords = newRecords;
            }
        };
    }]);
As can be seen, using $http I fetch the data from the data.json file. Now my issue is that when I call the get method of the data service, I get back empty records even though data.json is not empty.  
As I understand, $http.get() will return the data with some delay and hence when I call get, it is still not filled and hence I get empty values.  
How do I call the service and ensure that the data is filled when I am fetching it from the service?
 
     
     
    