$ionicLoading Question

I am using the factory method to get data from a rest service. My problem is that I would like to display the loading overlay while my get function is executing and hide it when completed. How would I do that in the scenario? Is it something I would do in the factory and not in the controller? I am pretty new to ionic and would appreciate the help. Thanks !!

.factory(‘OpinionFactory’, [’$http’, function($http) {

var dataFactory = {};

dataFactory.getopinions = function () {
    return $http.get(myUrl);
};
return dataFactory;

}])

.controller(‘OpinionsCtrl’, [’$scope’, ‘OpinionFactory’, function ($scope, opinionFactory) {

getOpinions();

function getOpinions() {

  opinionFactory.getopinions()
      .success(function (data) {
          $scope.opinions = data;
      })
      .error(function (error) {
          $scope.status = 'Unable to load customer data: ' + error.message;
      });
}

}])

I would suggest the use of anguar’s httpInterceptors. With the use of interceptors use can intercept AJAX calls before they are handed to the servers. You can intercept all your server calls and put code to show loading until response comes.