Skip to content

Instantly share code, notes, and snippets.

@niquola
Last active September 22, 2023 21:10
Show Gist options
  • Save niquola/5851861 to your computer and use it in GitHub Desktop.
Save niquola/5851861 to your computer and use it in GitHub Desktop.
Progress indication in angularjs, while promises :)
MyController = ($scope, $resource)->
$scope.items = $resource.query()
window.ngApp.directive 'progressLoader', ($filter) ->
restrict: "A"
scope: null
link: (scope, element, attributes) ->
watchCallback = (newValue, oldValue) ->
if newValue?.$resolved == false
element.show()
else
element.hide()
scope.$watch attributes.promise, watchCallback, true
<div class="loader" progress-loader promise="items"> Loading...do more with css :)</div>
<ul>
<li ng-repeat="item in items"> {{item.label}}</li>
</ul>
@ThomasBurleson
Copy link

I agree with @smmccrohan. Using promise="items" attribute is a distortion of the concept of promises.
Using ng-hide allows any process to update/modify that data model... this is a better approach AND it eliminates the need for the extra directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment