I'm working on an Ionic app and I have a login feature implemented. I want to display a spinner when the user clicks the login button, and hide it once the login process is complete. Here's my current code snippet: This is the scope function that triggers when the login button is clicked: $scope.doLogin = function(loginData) { console.log("in doLogin") $scope.submitted = true; if (loginData.$valid) { $ionicLoading.show({ template: '<ion-spinner class="spinner-energized" icon="spiral"></ion-spinner>', hideOnStateChange: true, duration: 2000 }); $location.url('/about'); } }; I want to modularize this functionality using AngularJS directives so that I can easily use it across multiple click events in my codebase. However, I'm unsure about how to approach this. You can find the code here: http://plnkr.co/edit/pi71uQunHSYMwONqlPTa?p=info Specifically, I want to encapsulate the following part into a directive for reusability: $ionicLoading.show({ template: '<ion-spinner class="spinner-energized" icon="spiral"></ion-spinner>', hideOnStateChange: true, duration: 2000 }); One challenge I'm facing is ensuring that the 'ionicLoading.show' is only triggered when 'loginData.$valid' evaluates to true. Any assistance or insights on how to achieve this would be highly appreciated. Thank you!