# $ionicLoading.show while resolving state objects

**URL:** <https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622>\
**Category:** uncategorized\
**Created:** [January 29, 2015, 6:21pm UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622 "2015-01-29T18:21:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hgo](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/hgo/32/75095_2.png) [@hgo](https://forum.ionicframework.com/u/hgo)\
**Post date:** [January 29, 2015, 6:21pm UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622/1 "2015-01-29T18:21:31Z")

</div>

I’m trying to show loading indicator if state needs to resolve a dependency.

`$rootScope.$on('loading:show', function (event,data) { $ionicLoading.show({ template:'Please wait..' }) })`

`$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { if (toState.resolve) { $rootScope.$broadcast('loading:show') }} )`

`$stateProvider.state('reservations', { url: '/reservations', resolve: { reservations: function (reservationService) { return reservationService.findAll(); } } })`

However the indicator never shows up. Do you have any idea?

Thanks…

---

<div class="post-metadata">

**Author:** ![rajul885](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@rajul885](https://forum.ionicframework.com/u/rajul885)\
**Post date:** [February 21, 2015, 12:00pm UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622/2 "2015-02-21T12:00:50Z")

</div>

Hey,  
Did you get solution this problem?

---

<div class="post-metadata">

**Author:** ![hgo](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/hgo/32/75095_2.png) [@hgo](https://forum.ionicframework.com/u/hgo)\
**Post date:** [February 24, 2015, 9:39am UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622/3 "2015-02-24T09:39:19Z")

</div>

Not yet. It’s interesting that when I try it in codepen, it’s working.

---

<div class="post-metadata">

**Author:** ![devstudio](https://avatars.discourse-cdn.com/v4/letter/d/51bf81/32.png) [@devstudio](https://forum.ionicframework.com/u/devstudio)\
**Post date:** [August 8, 2015, 3:55am UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622/5 "2015-08-08T03:55:39Z")

</div>

This is working for me, YMMV.

```
$rootScope.$on('loading:show', function () {
    $ionicLoading.show({
        template:'Please wait..'
    })
});

$rootScope.$on('loading:hide', function () {
    $ionicLoading.hide();
});

$rootScope.$on('$stateChangeStart', function () {
    console.log('please wait...');
    $rootScope.$broadcast('loading:show');
});

$rootScope.$on('$stateChangeSuccess', function () {
    console.log('done');
    $rootScope.$broadcast('loading:hide');
});
```

---

<div class="post-metadata">

**Author:** ![netchamp\_faris](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@netchamp\_faris](https://forum.ionicframework.com/u/netchamp_faris)\
**Post date:** [January 8, 2016, 5:13pm UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622/6 "2016-01-08T17:13:06Z")

</div>

@devstudio  
that doesnt work for me, the console log message shows up but the loading indicator does not.

---

<div class="post-metadata">

**Author:** ![miedeman](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@miedeman](https://forum.ionicframework.com/u/miedeman)\
**Post date:** [January 10, 2016, 1:21am UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622/7 "2016-01-10T01:21:38Z")

</div>

Do you also have this code (or similar) in your app to show the spinner when $http is used (in a service for example?)?

```
.config(function($httpProvider)
{
	$httpProvider.interceptors.push(function($rootScope)
	{
		return {
			
			//http request show loading
			request: function(config)
			{
				$rootScope.$broadcast('loading:show');
				return config;
			},
			
			//hide loading in case any occurred
			requestError: function(response)
			{
				$rootScope.$broadcast('loading:hide');
				return response;
			},
			
			//Hide loading once got response
			response: function(response)
			{
				$rootScope.$broadcast('loading:hide');
				return response;
			},
			
			//Hide loading if got any response error 
			responseError: function(response)
			{
				$rootScope.$broadcast('loading:hide');
				return response;
			}
		}
	})
})

```

When i comment the code above in my app and run it the spinner shows up while resolving the data in the state. Maybe this sets you on track for a solution?

---

<div class="post-metadata">

**Author:** ![logus](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/logus/32/108335_2.png) [@logus](https://forum.ionicframework.com/u/logus)\
**Post date:** [March 30, 2017, 7:19pm UTC](https://forum.ionicframework.com/t/ionicloading-show-while-resolving-state-objects/16622/8 "2017-03-30T19:19:41Z")

</div>

This solution just works perfect for me. You need to implement the event broadcaster in the run block and the $ionicLoading function on a global/main controller.
