Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic - Show spinner after button is pressed

This spinner option from ionic is spinning all the time Like here

<ion-spinner icon="spiral"></ion-spinner>

How to make the spinner spin only after user presses the button, not before!?

like image 861
lewis4u Avatar asked Jun 13 '16 11:06

lewis4u


2 Answers

You can try this also inside your controller

$scope.show = function() {
        $ionicLoading.show({
          template: '<p>Loading...</p><ion-spinner icon="android"></ion-spinner>'
        });
      };

      $scope.hide = function(){
        $ionicLoading.hide();
      }; 

You can call $scope.show($ionicLoading); to start the spinners and you can make it end with this $ionicLoading.hide();

of course you have to inject $ionicLoading in your controller.

It worked for me hope it will help you

like image 168
Mohan Gopi Avatar answered Nov 15 '22 01:11

Mohan Gopi


You can simply show and hide ion-spinner directive. In the codepen link you can change the button part and paste this:

<button type="submit" ng-click="click()" class="button button-block button-positive">
    <ion-spinner ng-hide="showing" class="spinner-energized"></ion-spinner>
    <span class="button-text">Click me!</span>
</button>

and add to MainCtrl

$scope.showing = true;
$scope.click = function(){
    $scope.showing = false;
}

so when you press the button spinner will show. Of course you need some logic to stop it but this is just to show you how you can handle this. Hope it helps.

like image 45
macrog Avatar answered Nov 15 '22 01:11

macrog