Skip to content

Instantly share code, notes, and snippets.

@pascalwhoop
Created July 6, 2015 11:35
Show Gist options
  • Save pascalwhoop/e5f07c3711fe4b3014ca to your computer and use it in GitHub Desktop.
Save pascalwhoop/e5f07c3711fe4b3014ca to your computer and use it in GitHub Desktop.
wait-bar directive for angular material design. Shows wait bar once showEvent is emitted on rootScope and hides it again once hideEvent is emitted
/**
* @ngdoc directive
* @name frontendApp.directive:equals
* @description
* A directive to show and hide a loading bar. it takes two attributes (show-event and hide-event) which must be the event names it should listen on on the rootScope.
*/
.directive('waitBar', ['$rootScope', function ($rootScope) {
return {
restrict: 'E', // only activate on element attribute
link: function (scope, elem, attrs) {
scope.visible = false;
scope.message = attrs.message;
// watch own value and re-validate on change
$rootScope.$on(attrs.showEvent, function () {
scope.visible = true;
});
$rootScope.$on(attrs.hideEvent, function () {
scope.visible = false;
});
},
template: '<div ng-show="visible"><p>{{message}}</p></p><md-progress-linear md-mode="indeterminate" flex></md-progress-linear></div>'
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment