I'm attempting to use the angular-busy directive to trigger a loading indicator on state change. The directive template takes a promise (cg-busy='myPromise'), and I'm using ui-router for my routing. What is the best way to trigger the loading indicator on state change from company.list to company.detail so that the indicator is shown while the promises are being resolved? My thought is to create a blank promise on $stateChangeStart, and pass that into the cg-busy template, but that doesn't seem to be working.
HTML:
<div cg-busy='myPromise'></div>
<div class="h1"><h1>Companies</h1>
</div>
<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered">
<tr class="h4">
<td>Company Name</td>
<td>Drugs owned</td>
</tr>
<tr ng-repeat="Item in List">
<td><a ui-sref=".detail.overview({ id:Item.id})">{{ Item.label }} <span ng-show="Item.parent_ticker.length"> ({{ Item.parent_ticker }})</span> </a></td>
<td>{{ Item.metric_applications_count }}</td>
</tr>
</table>
</table>
routes:
angular.module('company').config(function($stateProvider) {
$stateProvider.state('company', {
url: '/company',
abstract: true,
views: {
'nav': { templateUrl: 'app/main.nav.html' },
'main': { templateUrl: 'app/company/company.html' },
'list@company': { templateUrl: 'app/company/company.list.html', controller: 'CompanyListCtrl' },
'footer@': { templateUrl: 'app/main.footer.html' }
}
});
$stateProvider.state('company.list', {url: '',views: {} });
$stateProvider.state('company.detail', {
url: '/{id:[0-9]{1,4}-[0-9]{1,4}}',
resolve: {
Overview: function($stateParams, companyService){
var d = companyService.getOverview($stateParams.id);
return d;
},
Products: function($stateParams, companyService){
var d = companyService.getProducts($stateParams.id);
return d;
},
Revenues: function($stateParams, companyService){
var d = companyService.getRevenues($stateParams.id);
// not a promise
return d;
}
});
company ctrl:
angular.module('company').controller('CompanyListCtrl', function ($rootScope, $scope, $state, $stateParams, $q, utilService, companyService) {
$scope.List = companyService.getAll().$object;
$rootScope.$on("$stateChangeStart", function (ev, to, toParams, from, fromParams) {
$scope.myPromise = $q.defer();
console.log('stateChangeStart');
console.log($scope.myPromise);
});
});
redacted routes for brevity.