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> |
thx for simplification,
but i'm looking for generic solution
i don't want to guess about promise result.
This directive can be extended with animation and progress percentage, based on request statistics.
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
For this specific case (waiting on a list that's being used in a repeat), I think it would be cleaner to just use: