Last active
September 22, 2023 21:10
-
-
Save niquola/5851861 to your computer and use it in GitHub Desktop.
Progress indication in angularjs, while promises :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyController = ($scope, $resource)-> | |
$scope.items = $resource.query() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="loader" progress-loader promise="items"> Loading...do more with css :)</div> | |
<ul> | |
<li ng-repeat="item in items"> {{item.label}}</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.