$ionicLoading as a Service


#1

With the latest nightly, I am getting a $ionicLoading instance.hide() has been deprecated. Use $ionicLoading.hide(). error when calling .hide() on my instance of $ionicLoading. Now this is no longer supported, how should I go about using $ionicLoading as a service? I don’t really want to have to create a new $ionicLoading instance and specify my loading message in every single controller.

My old (and no longer supported) solution was:

.factory('LoadingService', function($rootScope, $ionicLoading) {
  return {
    show: function() {
      $rootScope.loading = $ionicLoading.show({
        content: "Loading...",
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 100
      });
    },
    hide: function() {
      $rootScope.loading.hide();
    }
  };
})

and I just injected LoadingService into my controllers and called show() and hide() on the LoadingService object… Any suggestions for DRY & nightly-compatible alternatives?


#2

I used your code and then changed it slightly to get rid of deprecation warning (no instantiation):

.factory('LoadingService', function($ionicLoading) {
return {
  show: function(content) {
    $ionicLoading.show({
      template: (angular.isDefined(content) ? content : 'Loading...')
    });
  },
  hide: function() {
    $ionicLoading.hide();
  }
};

})


$ionicLoading not working with beta 11