cgross / angular-busy

Show busy/loading indicators on any element during $http requests (or any promise).
http://cgross.github.io/angular-busy/demo
MIT License
1.44k stars 256 forks source link

cgBusy no longer accepts string ids to represent promises/trackers #59

Closed searope closed 9 years ago

searope commented 9 years ago

Hello, I have a table loaded dynamically and its rows can be expanded with AJAX calls on user clicks. I'd like to show spinner while these secondary data is loaded. But I cannot use one promise variable for that since it shows the spinner in all rows. So I've tried to create the promise variables on the fly when the parent table is loaded. But when I try to access the dynamic variables I'm getting the error in the subject. How could I work around this? html:

<div ng-repeat="link in table">
  <div ng-click="loadRow(link)">
    <div cg-busy="'p'+link.fromId+'-'+link.toId"></div>
  </div>
</div>

js:

$scope.loadRow(link){
  $scope['p'+link.fromId+'-'+link.toId] = $http.get('...');
}
cgross commented 9 years ago

The expression you're passing to cg-busy is evaluating to a string, not a promise. Thats why you're getting that error. Do this:

$scope.loadRow(link){
  if (!$scope.promises) {
    $scope.promises = {};
  }
  $scope.promises['p'+link.fromId+'-'+link.toId] = $http.get('...');
}
<div ng-repeat="link in table">
  <div ng-click="loadRow(link)">
    <div cg-busy="promises['p'+link.fromId+'-'+link.toId]"></div>
  </div>
</div>
searope commented 9 years ago

thank you!